首页 > 其他 > 详细

字符ASCII转换

时间:2018-11-02 01:02:11      阅读:141      评论:0      收藏:0      [点我收藏+]

实现效果:

技术分享图片

关键知识:

技术分享图片

实现代码:

 1     private void button1_Click(object sender, EventArgs e)
 2     {
 3         if (textBox1.Text != string.Empty) {//不为空
 4             if (Encoding.GetEncoding("unicode").//判断字是否为字符
 5                 GetBytes(new char[] { textBox1.Text[0] })[1] == 0)
 6             {       //转ASCII
 7                 textBox2.Text = Encoding.GetEncoding("unicode").
 8                     GetBytes(textBox1.Text)[0].ToString(); 
 9             }
10             else {
11                 textBox1.Text = string.Empty;
12                 MessageBox.Show("请输入正确字母");
13             }
14         }
15     }
16     private void button2_Click(object sender, EventArgs e)
17     {
18         if (textBox3.Text != string.Empty) { 
19             int temp;
20             if (int.TryParse(textBox3.Text, out temp))
21             {   //转换字符
22                 textBox4.Text = ((char)temp).ToString();
23             }
24             else {
25                 textBox1.Text = string.Empty;
26                 MessageBox.Show("请输入正确数字");
27             }
28         }
29     }

 

字符ASCII转换

原文:https://www.cnblogs.com/feiyucha/p/9893467.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!