c#字母与ASCLL码的转换

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;


namespace 字母与ASCLL码的转换
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }


        private void Form1_Load(object sender, EventArgs e)
        {
            groupBox1.Text = "字母与ASCLL码的转换";
            button1.Text = "转换为ASCLL码";
            button2.Text = "转换为字母";
        }


        private void button1_Click(object sender, EventArgs e)
        {
            if(textBox1.Text==" ")
            {
                MessageBox.Show("请输入需要转换的字母");
            }
            Encoding P_encod = Encoding.GetEncoding("unicode");
            byte[] P_byte=P_encod.GetBytes(textBox1.Text);
            textBox3.Text = P_byte[0].ToString();
            
        }


        private void button2_Click(object sender, EventArgs e)
        {
            int P_num;
            if (textBox2.Text == " ")
            {
                MessageBox.Show("请输入需要转换的数");
            }
            if(int.TryParse(textBox2.Text,out P_num))
            {
                textBox4.Text = ((char)P_num).ToString(); 
            }
        }
    }
}

encoding中文意思是编码,那在c#中必定是用来编码转换的

在这个程序中用到了encoding对象的GetEncoding方法

运行图

发布了24 篇原创文章 · 获赞 48 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/xiaokai1999/article/details/80408041