6

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?

3
  • 1
    How you you recognize it's ANSI rather than Windows-1252? Neither has the BOM header. Commented Nov 6, 2012 at 17:00
  • 1
    At the bottom of Notepad++ it show ANSI not Windows-1252 Commented Nov 6, 2012 at 17:05
  • That's what I thought. See shf301's answer then. Commented Nov 6, 2012 at 18:03

2 Answers 2

5

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.

Sign up to request clarification or add additional context in comments.

Comments

-1

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

2 Comments

Why would you expect different results from this than you would from Encoding.GetEncoding(1252)? Aren’t these effectively the same?
Your answer provides no useful information vs the previous, accepted, answer and is over a decade late. Don't try to be a necromancer.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.