标签:
实例场景,对于字符串:"AAAA AAA BBBB BBB BBB CCCCCCCC"。
1. 分隔为 “AAAA AAA” , "BBBB BBB BBB","CCCCCCCC"
2.分隔为 “AAAA" ,”AAA“,”BBBB“,"BBB","BBB",”CCCCCCCC“
实现代码:
void Main() { var str = "AAAA AAA BBBB BBB BBB CCCCCCCC"; // - split by multiple spaces(more than one) var val = System.Text.RegularExpressions.Regex.Split( str, @"\s{2,}"); System.Console.WriteLine(val); // - split by spaces(one or more) var val2 = System.Text.RegularExpressions.Regex.Split( str, @"\s{1,}"); System.Console.WriteLine(val2); }
标签:
原文地址:http://blog.csdn.net/lan_liang/article/details/46375573