C#中的ASCII转换
来源:互联网 发布:org.apache.cxf maven 编辑:程序博客网 时间:2024/06/06 14:24
C# 字符转ASCII码,ASCII码转字符
//字符转ASCII码:
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.");
}
}
ASCII码转字符:
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.");
}
}
//另一种写法
string str="abcd";
byte[] bytetest = System.Text.Encoding.Default.GetBytes(str.ToString());
//字符转ASCII码:
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.");
}
}
ASCII码转字符:
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.");
}
}
//另一种写法
string str="abcd";
byte[] bytetest = System.Text.Encoding.Default.GetBytes(str.ToString());
0 0
- C#中的ASCII转换
- c# ascii转换方法
- C# 十六进制转换ASCII
- ASCII 码表和字符在C#中的转换方法
- ASCII 码表和字符在C#中的转换方法大全
- ASCII 码表和字符在C#中的转换方法.
- C# Unicode和ascii转换
- C# string ASCII相互转换
- c#转换ASCII,很不错
- c#中字符与ASCII码转换
- C#字符串转换为ASCII码
- C#字符串和ASCII码的转换
- C#字母与ASCII码的转换
- C# 将图片转换为ASCii字符
- C# ASCII与字符串间相互转换
- C#字符与数字互相转换,字母转换成ASCII码,ASCII码转换字符
- C# 八进制数值字符串转换成ASCII 字符串相互转换
- c# 汉字转换成ASCII码及ASCII码转换成汉字代码
- iOS音频处理技术-TAAE
- 运行Keras例子程序:imdb_cnn.py
- 常用资料备忘
- Git学习笔记
- Merge Sorted Array(easy)
- C#中的ASCII转换
- 盲打
- ★【16.6.2】Codeforces Round #355 (Div. 2) A. Vanya and Fence
- iOS 屏幕方向
- Python装饰器与面向切面编程
- Convert.ToInt32(Object, IFormatProvider)的含义
- for循环创建UIButton,如何去修改边框颜色
- git and github 学习笔记
- Java编程练习目录