How to remove comma separated value from a string?

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

    // If you want to remove ALL occurences of the item, say "a" you can use

      String data = "a, b, c, d, a, e, f, q, a";
    
      StringBuilder Sb = new StringBuilder();
    
      foreach (String item in data.Split(',')) {
        if (!item.Trim().Equals("a", StringComparison.Ordinal)) {
          if (Sb.Length > 0) 
            Sb.Append(',');
    
          Sb.Append(item);
        }
      }
    
      data = Sb.ToString();
    

提交回复
热议问题