C#StringBuilder - 如何转义此字符串:

noe*_*ard 0 c# stringbuilder

<document.write("<SCR"+"IPT TYPE='text/javascript' SRC='"+"http"+(window.location.protocol.indexOf('https:')==0?'s':'')+"://"+gDomain+"/"+gDcsId+"/wtid.js"+"'><\/SCR"+"IPT>");
Run Code Online (Sandbox Code Playgroud)

我需要转义上面的字符串,以便将整个事物添加到StringBuilder但到目前为止我必须丢失一些东西,因为字符串终止不正确...

Ste*_*ane 7

你应该尝试这样的事情:

@"<document.write(""<SCR""+""IPT TYPE='text/javascript' SRC='""+""http""+(window.location.protocol.indexOf('https:')==0?'s':'')+""://""+gDomain+""/""+gDcsId+""/wtid.js""+""'><\/SCR""+""IPT>"");"
Run Code Online (Sandbox Code Playgroud)

在使用@作为字符串文字的前缀时,唯一需要的转义是将"字符"加倍.

希望这有帮助.