码迷,mamicode.com
首页 > 其他好文 > 详细

17._11本章小结及任务实施

时间:2016-06-26 21:02:22      阅读:162      评论:0      收藏:0      [点我收藏+]

标签:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
using System.Collections;

namespace _17._11本章小结及任务实施
{
    class Program
    {
        static void Main(string[] args)
        {
            string str = "我爱你,我的中国。我喜欢我要自学网";
            string pattern = @"[^\u4e00-\u9fa5]";
            Regex regex = new Regex(pattern);
            string chnstr = regex.Replace(str, "");//替换非中文字符
            Hashtable ht = new Hashtable();
            for(int i=0; i < chnstr.Length; i++)
            {
                int val = 1;
                if (ht.ContainsKey(chnstr[i]))
                {
                    val = Convert.ToInt32(ht[chnstr[i]]);
                    ++val;
                }
                ht[chnstr[i]] = val;
             
            }
            Console.WriteLine("原有的字符串是:" + str);
            Console.WriteLine("修剪后的字符串是:"+chnstr);
            foreach (DictionaryEntry de in ht)
            {
                Console.WriteLine("{0}----------{1}", de.Key, de.Value);
            }
            Console.Read();

        }
    }
}

 

17._11本章小结及任务实施

标签:

原文地址:http://www.cnblogs.com/zqyo2000z/p/5618435.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!