C# - Get ANSI code value of a character

北城余情 提交于 2019-12-24 03:47:07

问题


I'd like to retrieve the ANSI code value of a given character. E.g. when I now get the int value of the trademark character, I get 8482. Instead I would like to get 153, which is the value of the trademark character in codepage 1252.

Some help would be appreciated.

Jurgen


回答1:


Found it myself:

Encoding ansiEncoding = Encoding.GetEncoding(1252);
byte[] bytes = ansiEncoding.GetBytes(c);
int code = bytes[0];


来源:https://stackoverflow.com/questions/12370812/c-sharp-get-ansi-code-value-of-a-character

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!