Maxime
Maxime

Reputation: 467

Windows-1252 Encoding in StreamWriter return ANSI encoded file

I try to encode a string in Windows-1252 with a StreamWriter. The input string (dataString) is encode in UTF8.

StreamWriter sw = new StreamWriter(@"C:\Temp\data.txt", true, Encoding.GetEncoding(1252));
sw.Write(dataString);
sw.Close();

When I open the file in Notepad++ I get a ANSI file. I need a Windows-1252 encoded file.

Someone have an idea?

Upvotes: 6

Views: 30900

Answers (2)

Sergey Potapenko
Sergey Potapenko

Reputation: 1

Try... Encoding.GetEncoding("windows-1251")

Upvotes: 0

shf301
shf301

Reputation: 31394

Your file is Windows-1252 encoded. There is no data in the file of a non-Unicode to indicate how the file is encoded. In this case ANSI just means not Unicode. If you where to encode the as Russian/Windows-1251 and open it in Notepad++, Notepad++ would display it as ANSI as well.

See Unicode, UTF, ASCII, ANSI format differences for more info.

Upvotes: 5

Related Questions