[.net] Reading a spanish .txt file in C#

Started by
4 comments, last by Bob Janova 17 years, 11 months ago
Im using C# scripts for a spanish word game dictionary using Visual Studio C# 2005 (the free edition from microsoft) However the streamReader object wont recognize the spanish symbols like accents and such ( á é ñ) they are simply ignored and wont appear in the , Im using UTF8 to read but I cant get it to recognize those. Any advice on how to do this? Heres the part of the code with the problem

            TextReader tr = new StreamReader(@"palabrasn.txt");
            TextWriter tw = new StreamWriter(@"resultados.xml");
            ArrayList[] palabras=new ArrayList[15];
            palabras[c] = new ArrayList();
            while ((clinea = tr.ReadLine()) != null){
                  palabras.add(clinea);
}
Advertisement
Try changing the current culture to spanish :

System.Threading.Thread.CurrentCulture = new System.Globalization.CultureInfo("sp");
Did you save the Text file in Unicode?
Thanks, I tried to do this It sounds pretty logical, and I didnt knew you could do this, but it didnt work.

Btw, I used this one in the main function as this

Thread.CurrentThread.CurrentCulture = new system.Globalization.CultureInfo("es-MX");



Maybe this has to do with the StreamReader encodertype? how can I change that one? im using UTF8 which suposedly should work with spanish encoding.
Quote:Did you save the Text file in Unicode?


That was it! the text was saved as an ansi file, I saved it in UTF8 format and now it works, thanks!

Problem solved!
I think you can read non-UTF8 text files using Encoding.Default.

This topic is closed to new replies.

Advertisement