C#-获取字符的ANSI代码值 [英] C# - Get ANSI code value of a character

查看:474
本文介绍了C#-获取字符的ANSI代码值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想检索给定字符的ANSI代码值. 例如.当我现在获得商标字符的int值时,我得到8482. 相反,我想获得153,它是代码页1252中商标字符的值.

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.

我们将不胜感激.

于尔根

推荐答案

自己找到了它:

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

这篇关于C#-获取字符的ANSI代码值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆