开发者

Which encoding does Alt+Numpad keys generate?

开发者 https://www.devze.com 2022-12-26 03:38 出处:网络
In开发者_Go百科 short: For this code: Encoding.ASCII.GetBytes(\"‚\") I want the output to be 130, but this gives me 63.

In开发者_Go百科 short:

For this code:

Encoding.ASCII.GetBytes("‚")

I want the output to be 130, but this gives me 63.

I am typing the string using Alt+0130.


On my setup:

Encoding.ASCII.GetBytes("‚"); // 63
Encoding.Default.GetBytes("‚"); // 130

Of course 'default' could very well be environment-dependent...


When you try to encode the string using the ASCII encoding, it will be converted to a question mark as there is no such character in the ASCII character set. The character code for the question mark is 63.

You need to use an encoding that supports the character, to get it's actual character code.

One option is to use the Encoding.Default property to get the encoding for the system codepage, as David suggested. However as the system codepage can differ, it's not guaranteed to give the same result on all computers.

The unicode character code is 8218, which you can get by simply converting the character to an int:

int characterCode = (int)'‚';

As this is not depending on any system settings, you should consider if you can use that instead of the encoded byte value.

0

精彩评论

暂无评论...
验证码 换一张
取 消