0

I have a text file that contains a single word but it is with language : Arabic I want to extract it

My code is:

 string text = System.IO.File.ReadAllText(@"C:\CINPROCESSING\nom.txt");
 Console.WriteLine(text );

I have the result with unknown characters : ????

How i can fix it?

Thanks,

devtunis
  • 141
  • 13
  • 1
    1) Use GetEncoding(int codepage) and set right codepage. or 2) Save your file as UTF-8 in notepad. UTF-8 encoding worked propertly. – nick_n_a Jul 11 '16 at 10:59

5 Answers5

3

Setup right codepage for your text.

System.IO.File.ReadAllText(@"C:\CINPROCESSING\nom.txt",System.Text.Encoding.GetEncoding(codepage))

May be codepage=1256 (windows-arabic).

nick_n_a
  • 198
  • 15
  • And check Console.WriteLine("arabic م") may be http://stackoverflow.com/a/38305257/5727271 right and you must change console codepage. – nick_n_a Jul 11 '16 at 11:34
2

Your code reads the text correctly into the variable text. (Debug and See)

However, dispalying arabic characters in the windows Console is another issue (Check how to solve it Here)

Community
  • 1
  • 1
Zein Makki
  • 29,485
  • 6
  • 52
  • 63
1

You can try this: string text = System.IO.File.ReadAllText(@"C:\CINPROCESSING\nom.txt",Encoding.Default); Console.WriteLine(text);

0

Try specifying the encoding using this StreamReader constructor:

StreamReader arabic_reader = new StreamReader(filePath, System.Text.Encoding.UTF8, true);

OR

string text = System.IO.File.ReadAllText(@"C:\CINPROCESSING\nom.txt",Encoding.UTF8);
Sachu
  • 7,555
  • 7
  • 55
  • 94
0

Try :

StreamReader reader = new StreamReader(filePath, System.Text.Encoding.UTF8, true);

For reference: http://msdn.microsoft.com/en-us/library/ms143457.aspx

user1012506
  • 2,048
  • 1
  • 26
  • 45