• Advertisement
Sign in to follow this  

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

This topic is 4263 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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);
}

Share this post


Link to post
Share on other sites
Advertisement
Try changing the current culture to spanish :

System.Threading.Thread.CurrentCulture = new System.Globalization.CultureInfo("sp");

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement