我有一个关于拆分字符串的问题。我想拆分字符串,但是当在字符串中看到字符“”时,不要拆分并删除空格。
我的字符串:
String tmp = "abc 123 \"Edk k3\" String;";
结果:
1: abc
2: 123
3: Edkk3 // don't split after "" and remove empty spaces
4: String
我的结果代码,但我不知道如何删除“”中的空格
var tmpList = tmp.Split(new[] { '"' }).SelectMany((s, i) =>
{
if (i % 2 == 1) return new[] { s };
return s.Split(new[] { ' ', ';' }, StringSplitOptions.RemoveEmptyEntries);
}).ToList();
或者,但这没有看到“”,所以它分裂了一切
string[] tmpList = tmp.Split(new Char[] { ' ', ';', '\"', ',' }, StringSplitOptions.RemoveEmptyEntries);