Environment: Visual Studio 2008 SP1
I have the following line in my text file:
using (var reader = File.OpenText(@"c:\temp\DATA.txt"))
{
...
string textLine = "ist where [name]='Curaçao')"
}
Please notice the non-English character.
Whenever the reader.ReadLine gets to this point it turns it into a question mark in my console application.
Any ideas how to preserve that?
This is most likely an encoding issue – the
readeris using a different encoding to the one the file is in.Make sure both are using the same encoding.
File.OpenTextwill use theUTF8Encoding– if your file is in a different encoding, this may very well be the issue.To specify an encoding, construct
StreamReaderwith a constructor that takes anEncodingparameter:In the above example, I am using the Portuguese encoding.