4

According to MSDN vb.net uses this extended character set. In my experience it actually uses this:

alt text

  1. What am I missing? Why does it say it uses the one and uses the other?
  2. Am I doing something wrong?
  3. Is there some sort of conversion tool to the original character set?
4

3 回答 3

6

This behaviour is defined in the documentation of the Chr command:

The returned value depends on the code page for the current thread, which is contained in the ANSICodePage property of the TextInfo class in the System.Globalization namespace. You can obtain ANSICodePage by specifying System.Globalization.CultureInfo.CurrentCulture.TextInfo.ANSICodePage.

So, the output of Chr for values greater than 127 is system-dependent. If you want reproducible results, create the desired instance of Encoding by calling Encoding.GetEncoding(String), then use Encoding.GetChars(Byte()) to convert your numeric values into characters.

If you go up one level in the chart linked in your question, you will see that they do not claim that this chart is always the output of the Chr command:

The characters that appear in Windows above 127 depend on the selected typeface.

The charts in this section show the default character set for a console application.

Your application is a WinForm application, not a console application. Even in the console, the character set used can be changed (for example, by using the chcp command), hence the word "default".

For detailed information about the encodings used in .net, I recommend the following MSDN article: Character Encoding in the .NET Framework.

于 2010-11-16T15:16:09.323 回答
2

The first character set is Code Page 437 (CP437), the second looks like Code Page 1252 (CP1252) also known as Windows Latin-1.

I'd guess VB.Net is simply picking up the default encoding for the PC.

于 2010-11-16T14:35:43.220 回答
1

How did you write all this? Because usually, when you use a output stream function, you can specify the encoding going with it.

Edit: I know this is not C#, but you can see the idea...

You'd have to set the encoding of your filestream, by doing something like this: Setting the encoding when creating the filestream

于 2010-11-16T14:27:51.497 回答