我想寫一個正則表達式來分割以下字符串正則表達式分割字符串
"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