Strip double quotes from a string in .NET

后端 未结 12 2026
抹茶落季
抹茶落季 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 04:47

    If you only want to strip the quotes from the ends of the string (not the middle), and there is a chance that there can be spaces at either end of the string (i.e. parsing a CSV format file where there is a space after the commas), then you need to call the Trim function twice...for example:

    string myStr = " \"sometext\"";     //(notice the leading space)
    myStr = myStr.Trim('"');            //(would leave the first quote: "sometext)
    myStr = myStr.Trim().Trim('"');     //(would get what you want: sometext)
    

提交回复
热议问题