我有一個字符串,象這樣:C#字符串分割 - 破串起來在第二逗號
mystring = "test1, 1, anotherstring, 5, yetanother, 400";
myarray中可以是不同長度的。我想要做的是將字符串拆分爲:
{"test1, 1"}
{"anotherstring, 5}
{"yetanother, 400"}
這可能嗎?我嘗試了string[] newArray = mystring.Split(',')
,但是它以每個逗號分割,而不是我想要做的第二個逗號。
感謝您的幫助
的ZAP
我喜歡這個。我認爲它是最可讀的(即沒有數學),並且最不容易被一個錯誤等。+1 – spender 2010-07-15 10:43:14
一個比較簡單的正則表達式是@「\ w +,\ s + \ w +」 – 2010-07-15 10:48:05
@Jim:是的,它適用於特定字符串,但是例如用'「test,1,lost + found,2」或test「,1,2」'失敗。 – Guffa 2010-07-15 10:53:28