Question

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?
Was it helpful?

Solution

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.

OTHER TIPS

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.

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top