首页 > Windows开发 > 详细

C#拆分中文和数字字符串

时间:2020-07-29 10:46:37      阅读:113      评论:0      收藏:0      [点我收藏+]

比如要拆分“呵呵呵90909086676喝喝999”,下面当type=0返回的是中文字符串“呵呵呵,喝喝”,type=1返回的是数字字符串“90909086676,999”,

 private string GetStrings(string str,int type=0)
        {
            IList<string> strList = new List<string>();
            MatchCollection ms;
            if (type == 0)
            {
                ms = Regex.Matches(str, @"\D+"); 
            }
            else
            {
                ms = Regex.Matches(str, @"\d+");
            }
          
            foreach (Match m in ms)
            {
                strList.Add(m.Value);
            }
            return string.Join("",strList.ToArray());
        }

 

C#拆分中文和数字字符串

原文:https://www.cnblogs.com/bibi-feiniaoyuan/p/13395146.html

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