File ReadAllLines turns foreign language into gibberish (�)
Asked Answered
M

1

6

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);
Masqat answered 11/6, 2013 at 10:56 Comment(4)
What code are you using?Herbivorous
Do you provide an encoding when opening your files?Launceston
@Launceston Yes. "Encoding.Unicode"Masqat
Actually, the default for the files is ASCI. When I added Unicode it made it worse, but I think if I'll be able to convert the types to Unicode - things will work perfect. I'm trying to use Encoding.Convert but it's the fisrt time I'm doing that.Masqat
K
13

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

var myLines = File.ReadAllLines(@"C:\MyFile.txt",  Encoding.GetEncoding("Windows-1255"));
Katleen answered 11/6, 2013 at 11:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.