张磊(Avraber)

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

简繁体转换程序,输入简体,点击生成繁体,没有相应的繁体会有提示

namespace 火星文翻译器
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
              string Jian = "词库,见程序";
              string HXW = "词库,见程序";
              Dictionary<char ,char > dir=new Dictionary<char ,char >();
              for (int i = 0; i < Jian.Length; i++)
              {
                  dir.Add(Jian[i], HXW[i]);
              }
              string txt1 = textBox1.Text;
              StringBuilder sb = new StringBuilder();
              StringBuilder sb1 = new StringBuilder();
              for (int i = 0; i < txt1.Length; i++)
              {
                  if (dir.ContainsKey(txt1[i]))
                  {
                      string temp = Convert.ToString(dir[txt1[i]]);
                      sb.AppendFormat("{0}", temp);
                  }
                  else
                  {
                      sb1.AppendFormat("{0}", txt1[i]);
                  }
              }
              if (sb1.Length == 0)
              {
                  textBox2.Text = sb.ToString();
              }
              else
              {
                  MessageBox.Show(string.Format("{0}不能转换为繁体中文", sb1));
              }
              
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Clipboard.SetText(this.textBox2.Text);
            MessageBox.Show("复制成功,请用Ctrl+V在外部粘贴");
        }

        private void button3_Click(object sender, EventArgs e)
        {
            textBox1.Text = "";
            textBox2.Text = "";
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }
    }
}

image

山寨版词典,输入英文单词,可以得到对象的中文解释
山寨版词典namespace 山寨版词典
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            #region 词库
            string str = @" 词库,看程序";
            #endregion
            string[] strs = str.Split(new string[] { "  ", "\r", "\n", "   ", "    " }, StringSplitOptions.RemoveEmptyEntries);
            List<string> listchinese = new List<string>();
            List<string> listenglish = new List<string>();
            Dictionary<string, string> dir = new Dictionary<string, string>();
            for (int i = 0; i < strs.Length; i++)
            {
                if (i % 2 == 0)
                {
                    listenglish.Add(strs[i]);
                }
                else
                {
                    listchinese.Add(strs[i]);
                }
            }
            for (int i = 0; i < listenglish.Count; i++)
            {
                if (!dir.ContainsKey(listenglish[i]))
                {
                    dir.Add(listenglish[i], listchinese[i]);
                }
            }
            string strenglish = textBox1.Text;
            if (dir.ContainsKey(strenglish))
            {
                textBox2.Text = dir[strenglish];
                {
                }
            }
            else
            {
                MessageBox.Show("此单词不存在");
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            textBox1.Text = "";
            textBox2.Text = "";
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Clipboard.SetText(this.textBox2.Text);
            MessageBox.Show("复制成功,请用Ctrl+V在外部粘贴");
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }
    }
}
"; #endregion string[] strs = str.Split(new string[] { "", "\r", "\n", "", "" }, StringSplitOptions.RemoveEmptyEntries); List<string> listchinese = new List<string>(); List<string> listenglish = new List<string>(); Dictionary<string, string> dir = new Dictionary<string, string>(); for (int i = 0; i < strs.Length; i++) { if (i % 2 == 0) { listenglish.Add(strs[i]); } else { listchinese.Add(strs[i]); } } for (int i = 0; i < listenglish.Count; i++) { if (!dir.ContainsKey(listenglish[i])) { dir.Add(listenglish[i], listchinese[i]); } } string strenglish = textBox1.Text; if (dir.ContainsKey(strenglish)) { textBox2.Text = dir[strenglish]; { } } else { MessageBox.Show("此单词不存在"); } } private void button3_Click(object sender, EventArgs e) { textBox1.Text = ""; textBox2.Text = ""; } private void button2_Click(object sender, EventArgs e) { Clipboard.SetText(this.textBox2.Text); MessageBox.Show("复制成功,请用Ctrl+V在外部粘贴"); } private void Form1_Load(object sender, EventArgs e) { } } }
image
 
 


posted on 2012-07-01 23:49  张磊(Avraber)  阅读(340)  评论(0编辑  收藏  举报