Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

File ReadAllLines turns foreign language into gibberish (�)

Tags:

string

c#

hebrew

I am creating a tool that replaces some text in a text file. My problem is that File ReadAllLines turns the Hebrew characters into Gibberish (weird question marks �)

Does anyone know why this is happening? Note that I do have a problem with Hebrew in games and such.. And in Notepad, I can't save Hebrew documents. I can write Hebrew letters but when I save it tells me there's a problem with that.

EDIT - Tried this, but it only turned the Hebrew into regular question marks and not "special" ones-

string[] lines = File.ReadAllLines(fullFilenameDir);
byte[] htmlBytes = Encoding.Convert(Encoding.ASCII, Encoding.Unicode, Encoding.ASCII.GetBytes(String.Join("\r\n", lines)));
char[] htmlChars = new char[Encoding.Unicode.GetCharCount(htmlBytes)];
Encoding.Unicode.GetChars(htmlBytes, 0, htmlBytes.Length, htmlChars, 0);
like image 344
Kfir Eichenblat Avatar asked Jun 11 '13 10:06

Kfir Eichenblat


1 Answers

Try using the Windows-1255 code page to get the encoder.

var myLines = File.ReadAllLines(@"C:\MyFile.txt",  Encoding.GetEncoding("Windows-1255"));
like image 192
keyboardP Avatar answered Nov 05 '22 16:11

keyboardP