Strip double quotes from a string in .NET

后端 未结 12 2027
抹茶落季
抹茶落季 2020-12-24 04:16

I\'m trying to match on some inconsistently formatted HTML and need to strip out some double quotes.

Current:


         


        
12条回答
  •  生来不讨喜
    2020-12-24 05:03

    if you would like to remove a single character i guess it's easier to simply read the arrays and skip that char and return the array. I use it when custom parsing vcard's json. as it's bad json with "quoted" text identifiers.

    Add the below method to a class containing your extension methods.

      public static string Remove(this string text, char character)
      {
          var sb = new StringBuilder();
          foreach (char c in text)
          {
             if (c != character)
                 sb.Append(c);
          }
          return sb.ToString();
      }
    

    you can then use this extension method:

    var text= myString.Remove('"');
    

提交回复
热议问题