如何从一个数组中删除任何删除字符串的字符串和只有整数,而不是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