I have an ANSI-encoded file, and I want to convert the lines I read from the file to ASCII.
How do I go about doing this in C#?
EDIT : What if i used "BinaryReader"
BinaryReader reader = new BinaryReader(input, Encoding.Default);
but this reader takes (Stream, Encoding)
but "Stream" is an abstract! And where should I put the path of the file which he will read from ?
Best Solution
A direct conversion from ANSI to ASCII might not always be possible, since ANSI is a superset of ASCII.
You can try converting to UTF-8 using
Encoding
, though:Of course you can replace UTF8 with ASCII, but that doesn't really make sense since:
UPDATE:
In response to the updated question, you can use
BinaryReader
like this: