【问题标题】:How to make Response.Write Display special character like "<",">"如何使 Response.Write 显示特殊字符,如“<”、“>”
【发布时间】:2014-03-09 12:41:25
【问题描述】:

我想使用 Response.Write 使用 ASP.NET 在屏幕上显示一些文本 我创建了一个变量

String s = "There is some <hidden text> which is not visible";
Response.Write(s);

我发现浏览器只显示“有一些不可见” 任何写在符号 '' 之间的文本都会被浏览器忽略。

如何显示整个文本?

请指教。

【问题讨论】:

    标签: c# html asp.net html-escape-characters response.write


    【解决方案1】:

    你可以试试这个:

    String s = @"There is some <hidden text> which is not visible";
    Response.Write(s);
    

    【讨论】:

      【解决方案2】:

      使用HTML Encoding

      Server.HtmlEncode("There is some <hidden text> which is not visible");
      

      【讨论】:

      • 感谢@Emad 当我将它用作 Response.Write(Server.HtmlEncode("There are some which is not visible");)
      【解决方案3】:

      我不熟悉 C#,所以这可能行不通,但您可以使用 html 转义字符转义 &lt;&gt;

      &amp;#60;&lt;

      &amp;#62;&gt;

      所以不妨试试……

      String s = "There is some &#60;hidden text&#62; which is not visible";
      

      【讨论】:

      • 可能不得不以某种方式转义 C# 中的分号。
      • 完美这个工作:-) 在特殊字符也不起作用之前使用转义序列字符'/'
      猜你喜欢
      • 1970-01-01
      • 2015-08-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-02-12
      • 2019-10-14
      • 2012-02-13
      • 1970-01-01
      相关资源
      最近更新 更多