1

I am using below code to read a CSV file:

using (StreamReader readfile = new StreamReader(FilePath, Encoding.GetEncoding("iso-8859-1")))
{
 // some code will go here
}

There is a character œin a column of the CSV file. Which is getting converted to ? in output. How can i get this œ encoded correctly so that in output i will get same œ character not a question mark.

aloisdg
23.8k7 gold badges93 silver badges114 bronze badges
asked Feb 1, 2019 at 12:29
2
  • 1
    A question mark always means that the character has no valid representation in the desired encoding. You must use some other encoding to get it working, or be ready to replace that character with some other. Commented Feb 1, 2019 at 12:39
  • 1
    iso-8859-1 has no encoding for this character (U+0153 Œ LATIN SMALL LIGATURE OE), so your CSV file seems to use a different charset. Commented Feb 1, 2019 at 13:05

2 Answers 2

3

This is an encoding problem. Many non-Unicode encodings are either incomplete and translate many characters to "?", or have subtly different behavior on different platforms. Consider using UTF-8 or UTF-16 as the default. At least, if you can.

"windows-1252" is a superset of "ISO-8859-1". Try with Encoding.GetEncoding(1252).

Demo:

public static void Main()
{
 System.IO.File.AppendAllText("test","œ", System.Text.Encoding.GetEncoding(1252));
 var content = System.IO.File.ReadAllText("test", System.Text.Encoding.GetEncoding(1252));
 Console.WriteLine(content);
}

Try it online!

answered Feb 1, 2019 at 12:37
Sign up to request clarification or add additional context in comments.

Comments

1

The iso-8859-15 character set contain those symbols, as does the Windows-1252 codepage. However, be aware that 8859-15 redefines six other RARELY USED (or ASCII duplicate) chars that are in 8859-1, but so does Windows 1252. A quick web search will reveal those differences.

answered Apr 1, 2021 at 23:18

1 Comment

This post provides additional information/suitable alternative. This may not answer original question. It is suggested to post it as comment on original question.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.