How to remove comma separated value from a string?

后端 未结 10 1847
你的背包
你的背包 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 01:01

    var l = x.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList();
    l.Remove(OfferID.ToString());
    x = string.Join(",", l);
    

    Edit: Sorry, you're right. Remove doesn't return the original list. You need multiple statements. But you don't need to trim the end "," implicitly. You can remove that statement from your code as well as the check to see if the item is there or not. The Remove will take it out if it was found or simply return false if it was not found. You don't have to check existence. So remove the TrimEnd from the first and get rid of the second line below:

    offIdColl = my_Order.CustomOfferAppliedonOrder; //.TrimEnd(',');
    //if (offIdColl.Split(',').Contains(OfferID.ToString()))
    

提交回复
热议问题