Reputation: 141
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
Reputation: 61
You can try this: string text = System.IO.File.ReadAllText(@"C:\CINPROCESSING\nom.txt",Encoding.Default); Console.WriteLine(text);
Upvotes: 1
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
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
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
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