比如要拆分“呵呵呵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()); }
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/1630.html
標籤:C#
下一篇:設計模式之裝飾模式
