2011-05-26 66 views

回答

4

你必须要逃避字符串双引号这样

InputString = InputString.Replace("\"", """); 
0

你需要躲避引号:

InputString = InputString.Replace("\"","""); 
0

看来你正在尝试HTML编码一个字符串。如果你想成为100%的安全,而不是运行到后来与其他字符类似的问题,请尝试:

public static string HtmlEncode(string text) { 
    char[] chars = HttpUtility.HtmlEncode(text).ToCharArray(); 
    StringBuilder result = new StringBuilder(text.Length + (int)(text.Length * 0.1)); 

    foreach (char c in chars) { 
     int value = Convert.ToInt32(c); 
     if (value > 127) 
      result.AppendFormat("&#{0};",value); 
     else 
      result.Append(c); 
    } 

    return result.ToString(); 
} 

InputString = HtmlEncode(InputString); 

来自:http://www.codeproject.com/KB/recipes/htmlencodingcsharp.aspx