c# asc码和字母互相转换函数
来源:互联网 发布:淘宝刷砖平台 编辑:程序博客网 时间:2024/06/03 13:04
/// <summary>
/// convert the character to Asc code
/// </summary>
/// <param name="character"></param>
/// <returns></returns>
public static int Asc(string character)
{
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.");
}
}
/// <summary>
/// convert the asc code to character
/// </summary>
/// <param name="asciiCode"></param>
/// <returns></returns>
public static string Chr(int asciiCode)
{
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.");
}
}
/// convert the character to Asc code
/// </summary>
/// <param name="character"></param>
/// <returns></returns>
public static int Asc(string character)
{
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.");
}
}
/// <summary>
/// convert the asc code to character
/// </summary>
/// <param name="asciiCode"></param>
/// <returns></returns>
public static string Chr(int asciiCode)
{
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.");
}
}
- c# asc码和字母互相转换函数
- Java中ASC码与字符互相转换
- C#字符与数字互相转换,字母转换成ASCII码,ASCII码转换字符
- [HOWTO]ORACLE中如何实现ASC字符串和16进制串互相转换
- ASCⅡ码转换
- C# 字符串和byte的互相转换
- C# JSON串和对象互相转换
- C# Image和Byte[]互相转换
- C# List和String互相转换
- C# JSON串和对象互相转换
- C# Int 和 IntPtr 互相转换
- C# 图片和byte[]的互相转换
- C# LIST和STRING互相转换
- C# List和String互相转换
- C# LIST和STRING互相转换
- C# LIST和STRING互相转换
- C# LIST和STRING互相转换
- C# 图片和Base64字符串互相转换
- vc 中debug版程序正常 但release版崩溃
- C# MD5
- AS3 event flow 事件冒泡机制
- [Android] 获取Android设备的唯一识别码|设备号|序号|UUID
- PHP的ob_start();用法
- c# asc码和字母互相转换函数
- 均衡算法代码(java)(2)
- Oracle 角色管理
- SSAS处理时“找不到属性键”的解决办法
- 利用htmpParser获取网页内容以及网页上的图片地址
- js根据日期判断星座
- linux内核代码分段信息
- 插件11:上传文件
- 终于解决掉文件系统fwrite一个严重的bug