views:

500

answers:

1

Having trouble geting the encoding right in my silverlight application. I need support for western europe letters like æ,ø,å,â and so(Latin1??). But I can't get it right. What should be instead of SOMEENCODINGHERE? did try Encoding enc = Encoding.GetEncoding("Latin1"); but no names I used as param was recognized =( . If I use Encoding.Unicode tr.ReadLine() reads the whole file and convert it to Chinese for some reason.

    private Dictionary<int, string> InitDictionary()
    {
        var d = new Dictionary<int, string>();
        var sri = App.GetResourceStream(new Uri(fileDic, UriKind.Relative));
        using (TextReader tr = new StreamReader(sri.Stream, Encoding.SOMEENCODINGHERE))
        {
            int i = 0;
            string line;
            while ((line = tr.ReadLine()) != null)
            {
                d.Add(i++, line);
            }
        }
        return d;
    }
+1  A: 

If you really want ISO-Latin-1, you can use

Encoding.GetEncoding(28591);

But the normal Windows Western Europe code page is 1252:

Encoding.GetEncoding(1252);

Are you absolutely sure that's the encoding for your stream though? These days it's more common to use UTF-8. What's generating your text resource?

Jon Skeet
But GetEncoding want string as parameter not an integer
Qwark
Well there's *an* overload that takes a string - but at least in the desktop framework, there's an overload taking an integer. Does that not exist in Silverlight? Have you tried it?
Jon Skeet
Yes I have tried it, The file I have is a dictionary that I download from a 3rd party provider. And do not know the Encoding of. I think I going to write someting that convert the file to UTF-8.
Qwark