'windows-1255' is not a supported encoding name

孤街醉人 提交于 2019-12-20 05:01:25

问题


I'm writing a silverlight 5 application in which I need to read a text file from the user.

Here is a snippet of my code:

  using (StreamReader reader = new StreamReader(fileStream, Encoding.GetEncoding("windows-1255")))

But I get the exception: "'windows-1255' is not a supported encoding name". Why is that?

And then, how do I read a file in the "windows-1255" encoding? (Hebrew)


回答1:


There are not many supported encodings in Silverlight. Basically, you get UTF8 and UTF16, see http://msdn.microsoft.com/en-us/library/t9a3kf7c%28VS.95%29.aspx

You can read your file as binary then convert yourself to UTF (8 or 32, I don't know Hebrew). You'll need a table of all the characters (256), then you can loop on your input file and translate directly.




回答2:


i ran into this problem again,

And after lots and lots of Googleing i found this amazing tool!

http://www.hardcodet.net/2010/03/silverlight-text-encoding-class-generator

this little piece of art that was created by "Philipp Sumi (@phsumi)", takes the name or code page of a well known encoding, and creates a custom Encoding class which compiles under Silverlight.

it does so by reading the existing encoding in wpf, and redactor it to work under silverlight.



来源:https://stackoverflow.com/questions/13563973/windows-1255-is-not-a-supported-encoding-name

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!