HI字符串我有一個這樣的字符串:C#如何拆分包含數字陣列
string test = "1Hello World 2I'm a newbie 33The sun is big 176The cat is black";
我想拆分字符串,把陣列中的像這樣:
1 Hello World
2 I'm a newbie
33 The sun is big
176 The cat is black
結果可以在一個字符串[],ArrayList中,列表或LINQ
添加了什麼我試過,但它不工作..
ArrayList oArrayList = new ArrayList();
Regex oRegex = new Regex(@"\d+");
Match oMatch = oRegex.Match(test);
int last = 0;
while (oRegex.Match(test).Success)
{
oArrayList.Add(oMatch.Value + " " + test.Substring(last, oMatch.Index));
last = oMatch.Index;
test = test.Remove(0, oMatch.Index);
oMatch = oRegex.Match(test);
}
我希望你喜歡正則表達式,因爲我有一種感覺有些會很快顯示出來...... – BradleyDotNET
「結果可能在String [],ArrayList,List或Linq中」聽起來像一個作業問題 – lahsrah
可能不是也可能是「如何解析'node.InnerXml'(ToString()'的一些其他定義良好的格式/對象樹)結果的XY問題。 –