How to remove comma separated value from a string?

后端 未结 10 1848
你的背包
你的背包 2021-01-03 00:13

I want to remove a comma separated value from the string..

suppose I have a string like this

string x=\"r, v, l, m\"

and i want to

10条回答
  •  攒了一身酷
    2021-01-03 00:54

    Not quite sure if this is what you mean, but this seems simplest and most readable:

            string x = "r, v, l, m";
            string valueToRemove = "r";
            var result = string.Join(", ", from v in x.Split(',')
                                           where v.Trim() != valueToRemove
                                           select v);
    

    Edit: like Bob Sammers pointed out, this only works in .NET 4 and up.

提交回复
热议问题