0

I am using this code: string[] readed = File.ReadAllLines(path); and everything that isn't in english fo example ěščřžýáíé will pop up like ?????????. I don't know what to do with it, and how do I read it as normal letter

  • 3
    What's the encoding of the file? UTF8? And where do you see the "?" characters - a console, a Windows Forms TextBox or ...? – Klaus Gütter Dec 18 '20 at 15:13
  • The simple answer is: read the file with the same encoding that was used to write the file. If you're not sure what that is, this site (https://nlp.fi.muni.cz/projects/chared/) can sometimes be useful, though I'm not sure how fool-proof it is. It could also be a display issue. For example, console applications will display Japanese as ??? unless you tell them to use the correct encoding to display the text. Even after that you need the right font. – ProgrammingLlama Dec 18 '20 at 15:14
  • 1
    Does this answer your question? [C# Help reading foreign characters using StreamReader](https://stackoverflow.com/questions/592824/c-sharp-help-reading-foreign-characters-using-streamreader) – user_cr Dec 18 '20 at 15:14

1 Answers1

1

There should be no problem with reading but with writing, there could be some problem so when you write you add Encoding.Unicode to the write command.

Writing Example:

    string myText = "my string";
    string filePath = "c:\\demo\demofile.txt";
    
    File.WriteAllText(filePath , myText , Encoding.Unicode);

With the reading, Please be sure that your file is saved in a healthy way (Saved by selecting the right Encoding like in the picture below).

Sample Text File

Useme Alehosaini
  • 2,998
  • 6
  • 18
  • 26