I have a few lines that contain special characters like these lines:
CommunautéFinancièreAfricaineBEACFranc(XAF) CommunautéFinancièreAfricaineBCEAOFranc(XOF)
But, when I write those lines into a text file, I get this as a result:
CFACommunaut�Financi�reAfricaineBEACFranc CFACommunaut�Financi�reAfricaineBCEAOFranc
This is how I write the lines:
File.WriteAllLines(@"c:\file5.txt", lines);
I also tried the 3rd parameter of File.WriteAllLines()
by passing an Encoding
. But that didn't help either.
File.WriteAllLines(@"c:\file5.txt", lines, Encoding.UTF8);
File.WriteAllLines(@"c:\file5.txt", lines, Encoding.ASCII);
This is how I read all lines:
File.ReadAllLines(@"C:\file4.txt").ToList()
.ForEach(g =>
lines.Add(g.ToString()
.Replace("/", string.Empty)
.Replace("(", string.Empty)
.Replace(")", string.Empty))
);
The crazy thing is, the characters are displayed perfectly fine in another text file (file4.txt) where I read everything in.