c# read hebrew from text file

笑着哭i 提交于 2019-12-24 05:43:40

问题


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:


  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.
  2. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!