问题
I want to converter all special characters into Html encoded characters.
I found many post related to used HttpUtility.HtmlEncode();
,
but it's only convert some of special characters like "&", "<", ">"
.
Is there any way to convert all special character like "š","Ø","þ","›","Ù"
into Html entity using C# or javascript?
回答1:
The Microsoft AntiXss Library can accomplish this;
string p = Microsoft.Security.Application.Encoder.HtmlEncode("aaa <b>sdf</b> š,Ø,þ,›,Ù", true);
Response.Write(p);
For
aaa <b>sdf</b> š,Ø,þ,›,Ù
回答2:
you can also do as follows without AntiXSS
public static string HtmlEncode (string text)
{
string result;
using (StringWriter sw = new StringWriter())
{
var x = new HtmlTextWriter(sw);
x.WriteEncodedText(text);
result = sw.ToString();
}
return result;
}
回答3:
Yes.Using javascript Escape them.
document.write(escape("3423424242<><><$$"));
来源:https://stackoverflow.com/questions/17106949/convert-special-characters-into-html-encoded-characters