• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 270
  • Last Modified:

Foraing characters missing when I read a Text file

Here it is a simply routine to load a file into a Hashtable, everything works fine, but when I use some characters in text file like ñ, á,é,í,ó,ú
these characters doesn't appear in the read strings.

I create the text file with Visual Studio.NET 2003 Pro.

Can someone help me?

LoadFromFile(Hashtable aTable, string aFileName){
                          FileInfo sesFile = new FileInfo(aFileName);
                  if (!sesFile.Exists) return false;
                  string [] data;
                  string lin;
                  StreamReader str = sesFile.OpenText();
                  try{
                        aTable.Clear();
                        while ((lin=str.ReadLine())!=null){
                              lin = lin.Trim();
                              if ((lin != "") && (lin.IndexOf(';') != 0)){
                                    data = lin.Split('=');
                                    aTable.Add(data[0].Trim(), data[1].Trim());
                              }
                        }
                  }
                  finally{
                        str.Close();
                  }
                  return true;
            }

Text file:
String1=León
String2=Niño.

In code you get:
String1=Len  (Missing ó)
String2=Nio  (Missing ñ)

Thanks
0
mak730
Asked:
mak730
1 Solution
 
BurntSkyCommented:
Add an encoding parameter to the StreamReader's constructor:

StreamReader str = new StreamReader(sesFile.OpenText(), Encoding.GetEncoding("ISO-8859-1"));

I'm not sure exactly what encoding your file is using, so swap out "ISO-8859-1" for whatever it is.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now