0

I have a text file which contains the char ¿ when I use the ReadAllText function to get the txt file text: the function changes the char ¿ to ? How can I get that char? Should I use another function?

Dag Høidahl
  • 7,873
  • 8
  • 53
  • 66

3 Answers3

0

The file is likely in an encoding the method cannot detect automatically (most encodings cannot be reliably detected anyways). Use the overload that lets you specify an encoding and specify the correct encoding for the file.

Matti Virkkunen
  • 63,558
  • 9
  • 127
  • 159
0

You should provide the encoding as second parameter like:

File.ReadAllText("file path", Encoding.UTF8);

Here is the list of encoding.

Shaharyar
  • 12,254
  • 4
  • 46
  • 66
0

Problem with encodings

Try to use Encoding.GetEncoding("iso-8859-1") for spanish characters.

File.ReadAllText("file path", Encoding.GetEncoding("iso-8859-1"));
Community
  • 1
  • 1
Valentin
  • 5,380
  • 2
  • 24
  • 38