Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/256.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 替换aspx c中的引号_C#_Asp.net_Quotes - Fatal编程技术网

C# 替换aspx c中的引号

C# 替换aspx c中的引号,c#,asp.net,quotes,C#,Asp.net,Quotes,在aspx第c页中,我对这个字符串有问题 sb.Append("window.location.href ='Default.aspx?a=" + a.SelectedItem.Value.ToString().Replace("'", "\'") + "&Date=" + decValue.ToString() + "';"); 如果在下拉列表字符串中的选定值中,我有引号,则预期会出现错误 我试过使用替换字符串但没有成功,你能帮我吗 即使这样也不行 Replace("\"","\\"

在aspx第c页中,我对这个字符串有问题

sb.Append("window.location.href ='Default.aspx?a=" + a.SelectedItem.Value.ToString().Replace("'", "\'") + "&Date=" + decValue.ToString() + "';");
如果在下拉列表字符串中的选定值中,我有引号,则预期会出现错误

我试过使用替换字符串但没有成功,你能帮我吗

即使这样也不行

Replace("\"","\\" + "\"")
我错过了什么

这个代码怎么了


提前感谢您。

在您的情况下,您必须使用:

a.SelectedItem.Value.ToString().Replace("\'", "\\" + "\'") 
替换“,\”将不起作用,因为C字符串中的\表示转义字符,例如换行符的\n。要表示反斜杠,需要像这样对其进行双重转义

.Replace("'", "\\'")
或者,您可以使用如下字符串文字:

.Replace("'", @"\'")