1

如何"Replace & with &"在 aspx 页面的标签或文本框中显示文本?当我放入Text="Replace & with &"aspx 页面时,我得到的输出是“用 & 替换 &”

4

2 回答 2

3

使用HttpUtility.HtmlEncode("&");这始终有效,并且生成的代码更具可读性。

于 2011-03-15T21:08:34.033 回答
1

替换&&

Text = "Replace & with &";

您还可以使其适用于任何角色,而不仅仅是&

string s = "<";
Text = HttpUtility.HtmlEncode("Replace " + s +
                              " with " + HttpUtility.HtmlEncode(s));
于 2011-03-15T21:06:16.900 回答