Sign in to follow this  

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

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){

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
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this