我想写一个正则表达式来分割以下字符串正则表达式分割字符串
"17. Entertainment costs,16. Employee morale, health, and welfare costs,3. Test"
进入
17. Entertainment costs
16. Employee morale, health, and welfare costs
3. Test
注意逗号第二的字符串中。
我想
static void Main(string[] args) {
Regex regex = new Regex(",[1-9]");
string strSplit = "1.One,2.Test,one,two,three,3.Did it work?";
string[] aCategories = regex.Split(strSplit);
foreach (string strCat in aCategories) {
System.Console.WriteLine(strCat);
}
}
但#的不来通过
1.One
.Test,one,two,three
.Did it work?
通过split,“[1-9]”,你永远不会得到数组aCategories中的数字。也许试着找到“,[1-9]”的索引,然后用它来保持子串,从而保持数字? – Justmaker 2012-03-05 14:36:53