(Sorry if this is a dupe)
I've just spent a long time trying to read a text file correctly.
Having started with File.ReadAllText(path)
and getting screwed-up characters, I tried several variants of File.ReadAlltext(path, Encoding)
after which I got bogged down trying to analyse my input files to work out which byte was the problem, etc.
In desperation I tried File.ReadAllText(path, Encoding.Default)
, which worked!
I'm now struggling to understand why the default value is apparently only the default value if you specify it.
(My cut-down test string was +4433ç
, I saved it in notepad as ANSI - though with Swiss French regional settings...)
Encoding.Default is the system's ANSI codepage.
What File.ReadAllText does if you don't specify an encoding is this:
So the only way to get the system's ANSI codepage is to explicitly specify Encoding.Default.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With