C#中怎么获得一个字符的ASCII码,以及怎么把ASCII码转化为相应的字符,小弟刚学,请教一下,谢谢
很感谢一楼的回答,但我感觉不直接(VB.NET中有Chr()和Asc()感觉用的很方便),有没有C#自带的方法来实现呀!...
很感谢一楼的回答,但我感觉不直接(VB.NET中有Chr()和Asc()感觉用的很方便),有没有C#自带的方法来实现呀!
展开
2个回答
展开全部
private void TestChar() {
char ch = ''a''; short ii = 65;
this.textBox1.Text = "";
this.textBox1.AppendText("The ASCII code of \''" + ch + "\'' is: " + (short) ch + "\n");
this.textBox1.AppendText("ASCII is " + ii.ToString() + ", the char is: " + (char) ii + "\n");
char cn = ''中''; short uc = 22478;
this.textBox1.AppendText("The Unicode of \''" + cn + "\'' is: " + (short) cn + "\n");
this.textBox1.AppendText("Unicode is " + uc.ToString() + ", the char is: " + (char) uc + "\n");
}
它的运行结果是
The ASCII code of ''a'' is: 97
ASCII is 65, the char is: A
The Unicode of ''中'' is: 20013
Unicode is 22478, the char is: 城
char ch = ''a''; short ii = 65;
this.textBox1.Text = "";
this.textBox1.AppendText("The ASCII code of \''" + ch + "\'' is: " + (short) ch + "\n");
this.textBox1.AppendText("ASCII is " + ii.ToString() + ", the char is: " + (char) ii + "\n");
char cn = ''中''; short uc = 22478;
this.textBox1.AppendText("The Unicode of \''" + cn + "\'' is: " + (short) cn + "\n");
this.textBox1.AppendText("Unicode is " + uc.ToString() + ", the char is: " + (char) uc + "\n");
}
它的运行结果是
The ASCII code of ''a'' is: 97
ASCII is 65, the char is: A
The Unicode of ''中'' is: 20013
Unicode is 22478, the char is: 城
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询