如何從一個數組中刪除任何刪除字符串的字符串和只有整數,而不是C#從數組
string[] result = col["uncheckedFoods"].Split(',');
我
[0] = on; // remove this string
[1] = 22;
[2] = 23;
[3] = off; // remove this string
[4] = 24;
我想
[0] = 22;
[1] = 23;
[2] = 24;
我試圖
var commaSepratedID = string.Join(",", result);
var data = Regex.Replace(commaSepratedID, "[^,0-9]+", string.Empty);
但是有一個逗號第一個元素之前,有沒有更好的方法來消除串?
我對這個知之甚少,所以在效率方面比正則表達式更好呢? – Sean83
謝謝,工作正常,SO系統設計爲等待5分鐘以接受您的答案。 – stom
@ Sean83在這種情況下,它應該比RegEx更快 – fubo