C# ASCII码与字符之间相互转化
2014-05-25 22:04
148 查看
public int Asc(string character) /*字符转化为ASCII*/ { if (character.Length == 1) { System.Text.ASCIIEncoding asciiEncoding = new System.Text.ASCIIEncoding(); int intAsciiCode = (int)asciiEncoding.GetBytes(character)[0]; return (intAsciiCode); } else { throw new Exception("Character is not valid."); } } public string Chr(int asciiCode) /*ASCII 转化为 字符*/ { if (asciiCode >= 0 && asciiCode <= 255) { System.Text.ASCIIEncoding asciiEncoding = new System.Text.ASCIIEncoding(); byte[] byteArray = new byte[] { (byte)asciiCode }; string strCharacter = asciiEncoding.GetString(byteArray); return (strCharacter); } else { throw new Exception("ASCII Code is not valid."); } }
相关文章推荐
- 字符、字符串与数值之间的相互转化
- 字符串、字符数组、list之间相互转化
- 十六进制字符串 与 所有字符(中文)之间的相互转化
- 数字字符与数字之间的相互转化
- JavaScript--常用的---对象-数组-字符串之间的相互转化
- Class 和 xml 之间的相互转化
- 使用springMVC注解@ResponseBody与jackson工具类在ajax请求中实现对象与json之间的相互转化
- C++中子类和父类之间的相互转化
- Python数字与字符之间的相互转换
- 用Gson实现json与对象、list集合之间的相互转化
- Activity之间的相互转化
- int、char、String之间的相互转化
- java之文件与base64字符之间的相互转换
- 完成一程序演示字符数组、C风格字符串、std::string和MFC中的Cstring类型之间的相互转换
- String StringBuffer 字符数组 的相互转化
- Linux时间戳转化命令-时间戳与具体时间之间相互转化
- 小数与分数之间相互转化
- int与CString,char*与CString,float与CString之间的相互转化
- 几个多字节和UNICODE及UTF-8之间相互转化的函数
- java之文件与base64字符之间的相互转换