将字符串拆分为数组,删除空格

Le *_*ung 5 .net c# arrays string split

我有一个关于拆分字符串的问题.我想拆分字符串,但在字符串中看到字符""然后不拆分并删除空格.

我的字符串:

String tmp = "abc 123 \"Edk k3\" String;";
Run Code Online (Sandbox Code Playgroud)

结果:

1: abc
2: 123
3: Edkk3  // don't split after "" and remove empty spaces
4: String
Run Code Online (Sandbox Code Playgroud)

我的结果代码,但我不知道如何删除""中的空格

var tmpList = tmp.Split(new[] { '"' }).SelectMany((s, i) =>
                {
                    if (i % 2 == 1) return new[] { s };
                    return s.Split(new[] { ' ', ';' }, StringSplitOptions.RemoveEmptyEntries);
                }).ToList();
Run Code Online (Sandbox Code Playgroud)

或者这不会看到"",所以它会分裂一切

string[] tmpList = tmp.Split(new Char[] { ' ', ';', '\"', ',' }, StringSplitOptions.RemoveEmptyEntries);
Run Code Online (Sandbox Code Playgroud)

Ser*_*eyS 8

添加.Replace("","")

String tmp = @"abc 123 ""Edk k3"" String;";
var tmpList = tmp.Split(new[] { '"' }).SelectMany((s, i) =>
{
    if (i % 2 == 1) return new[] { s.Replace(" ", "") };
    return s.Split(new[] { ' ', ';' }, StringSplitOptions.RemoveEmptyEntries);
}).ToList();
Run Code Online (Sandbox Code Playgroud)