devtunis
devtunis

Reputation: 141

How read form file Text language Arabic

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,

Upvotes: 0

Views: 2660

Answers (5)

Mohammad Jihad Helal
Mohammad Jihad Helal

Reputation: 61

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

Upvotes: 1

Zein Makki
Zein Makki

Reputation: 30052

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)

Upvotes: 2

nick_n_a
nick_n_a

Reputation: 206

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

Upvotes: 3

user1012506
user1012506

Reputation: 2118

Try :

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

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

Upvotes: 0

Sachu
Sachu

Reputation: 7766

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);

Upvotes: 0

Related Questions