Im reading a file with ReadAllText
String[] values = File.ReadAllText(@"c:\\c\\file.txt").Split(';'); int i = 0; foreach (String s in values) { System.Console.WriteLine("output: {0} {1} ", i, s); i++; }
If I try to read some files, I sometimes get the wrong character (for ΓΓΓΓ ...). The result is similar to "?", Because there are some encoding problems:
output: 0 TEST output: 1 A??O?
One solution would be to set the encoding to ReadAllText, you could say something like ReadAllText(@"c:\\c\\file.txt", Encoding.UTF8)
, which could fix the problem. But what if I still will? "how is the way out? What if I donβt know the encoding of the file? And what if each file received a different encoding? What would be the best way to do this with C #? Thank you
source share