I am reading lines from a CSV file using C#. However, the text that is read is incorrectly encoded. I have tried to convert it to UTF8 but to no avail.
string type_of_loan = System.Text.Encoding.UTF8.GetString(Encoding.GetEncoding("iso-8859-1").GetBytes(lineParts[5]));
I opened the file in an editor and it renders correctly when I open it using Western Latin 1 (iso-8859-1), but originally it says it is in Western Roman encoding and using that encoding I am getting the faulty characters to display as shown in the attached images.
Note that the weird question mark character shows up in C# even before it is saved to the DB.
I am expecting the swedish character "å" in its place.
This solved it:
var linesInFile = sftp.ReadLines(file.FullName, Encoding.GetEncoding("iso-8859-1"));
Thanks @ckuri
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.