从一个字符串.NET中剥去双引号 [英] Strip double quotes from a string in .NET
问题描述
我想匹配一些不一致的HTML格式,需要剥离出一些双引号。
I'm trying to match on some inconsistently formatted HTML and need to strip out some double quotes.
电流:
<input type="hidden">
目标:
<input type=hidden>
这是错误的,因为我不是逃避它正确的:
This is wrong because I'm not escaping it properly:
S = s.Replace(,);
s = s.Replace(""","");
这是错误的,因为没有空白字符的字符(据我所知):
This is wrong because there is not blank character character (to my knowledge):
s = s.Replace('"', '');
什么是语法/转义字符组合与一个空字符串替换双引号?
What is syntax / escape character combination for replacing double quotes with an empty string?
推荐答案
我觉得你的第一行会的实际工作,但我认为你需要包含一个一个串的四个引号(VB中至少):
I think your first line would actually work but I think you need four quotation marks for a string containing a single one (in VB at least):
s = s.Replace("""", "")
对于C#你必须用一个反斜杠逃脱引号:
for C# you'd have to escape the quotation mark using a backslash:
s = s.Replace("\"", "");
这篇关于从一个字符串.NET中剥去双引号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!