我通过javascript创建一个字符串数组传递值 “621:1622:1623:1624:1,”
我不知道如何从具有不同功能的字符串数组中取消“:1”或:2
char[] delimiterChars = { '1' };
char[] delimiterChars = { ':' };
string[] words = text.Split(delimiterChars);
string text = "621:1,622:1,623:1,624:1,";
string[] words = text.Split(delimiterChars);
System.Console.WriteLine("{0} words in text:", words.Length);
string save = "";
foreach (string s in words)
{
System.Console.WriteLine(s);
}
答案 0 :(得分:2)
使用String.Split(String[], StringSplitOptions)重载:
string[] delimiterStrings = new []{ ":1," };
string text = "621:1,622:1,623:1,624:1,";
string[] words = text.Split(delimiterStrings, StringSplitOptions.RemoveEmptyEntries);
结果:
文字中的4个字: 621 622 623 624