We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 3 years ago.
Improve this questionIs there any library that can be used to decode Shift JIS text on Silverlight?
I was able to port Mono's implementation to .NET in less than an hour. This is the (minimal?) set of classes that needs to be ported (sorted by dependency):
I18N.Common.Strings
I18N.Common.MonoEncoding
I18N.CJK.CodeTable
I18N.CJK.DbcsConvert
I18N.CJK.DbcsEncoding
I18N.CJK.JISConvert
I18N.CJK.CP932
Additionally, the following file needs to be copied (loaded in the constructor of I18N.CJK.CodeTable
):
- jis.table
The class that implements the "shift_jis" encoding is I18N.CJK.CP932
. Note that it must be instantiated manually, not through Encoding.GetEncoding()
.
I found some info here:
http://www.eggheadcafe.com/community/aspnet/14/14621/covert-shiftjis-to-unicode.aspx
This is the sample C# code from the link above (credits to Peter Bromberg). I cannot say for sure that it will work in Silverlight. I suppose it all depends on whether Encoding.GetEncoding("shift-jis") is available in SL:
public class FileConverter
{
const int BufferSize = 8096;
public static void Main(string[] args)
{
if (args.Length != 2)
{
Console.WriteLine
("Usage: FileConverter <input file> <output file>");
return;
}
//NOTE: you may need to use " Encoding enc = Encoding.GetEncoding("shift-jis"); " for non-standard code pages
// Open a TextReader for the appropriate file
using (TextReader input = new StreamReader
(new FileStream (args[0], FileMode.Open),
Encoding.UTF8))
{
// Open a TextWriter for the appropriate file
using (TextWriter output = new StreamWriter
(new FileStream (args[1], FileMode.Create),
Encoding.Unicode))
{
// Create the buffer
char[] buffer = new char[BufferSize];
int len;
// Repeatedly copy data until we've finished
while ( (len = input.Read (buffer, 0, BufferSize)) > 0)
{
output.Write (buffer, 0, len);
}
}
}
}
}
精彩评论