分享

VA14.3 小结

 时间剧毒 2019-04-29

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;

using System.Text.RegularExpressions;

using System.Collections;

namespace VA14.___小结

{

    public partial class Form1 : Form

    {

        public Form1()

        {

            InitializeComponent();

        }

        private void button1_Click(object sender, EventArgs e)

        {

            //中文出现的次数

            string str = "这是一行新,的语句SQL新新ee新";

            string pattern = @"[^\u4e00-\u9fa5]";

            Regex regx = new Regex(pattern );

            string chnstr = regx.Replace(str,"");   //只包含中文

            Hashtable ht = new Hashtable();

            for (int i = 0; i < chnstr.Length; i++)

            {

                int val = 1;

                if (ht.ContainsKey(chnstr[i]))   //判断Hashtable Key 存在  chnstr[i]代表的值否

                {

                    val = Convert.ToInt32(ht[chnstr[i]]);       //根据 Key 转 Values

                    val++;

                }

                    ht[chnstr[i]] = val;

            }

            textBox1.Text += "原:" + str + "\r\n";

            textBox1.Text += "现:" + chnstr + "\r\n";

            textBox1.Text += "========================================================\r\n";

            foreach (DictionaryEntry myboj in ht)

            {

                textBox1.Text += "键值为:" + myboj.Key + ",值为:" + myboj.Value + "\r\n";

            }

        }

        private void Form1_Load(object sender, EventArgs e)

        {

        }

        private void textBox1_TextChanged(object sender, EventArgs e)

        {

        }

    }

}

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多