问题
I wrote a text file in the Hebrew language . When I present the contents of the file in C # I do not see what I wrote - I understand that it is tied to Unicode , but I do not really understand it . Help , anyone?
string mymail = File.ReadAllText(@"C:\mail\mail.txt");
MessageBox.Show(mymail);
This is the result :
��� ����� ��� �� ��������� ������� ���� �� ������
回答1:
- Close your file and re-open it, make sure what you typed is actually persisted in your file. Using the default notepad app in Windows will usually default to ASCII so the characters will not be persisted correctly on disk and so it won't be retrieved correctly either.
You are missing your encoding, its probably defaulting to ASCII.
string mymail = File.ReadAllText(@"C:\mail\mail.txt", System.Text.Encoding.UTF8);
MessageBox.Show(mymail);
回答2:
string mymail = File.ReadAllText(@"C:\mail\mail.txt", System.Text.Encoding.GetEncoding("windows-1255"));
MessageBox.Show(mymail);
来源:https://stackoverflow.com/questions/32724294/c-sharp-read-hebrew-from-text-file