带有HTML实体名称的HtmlEncode,可以吗? [英] HtmlEncode with HTML entity name, is it possible?
问题描述
我正在使用以下方法对Spanish
中的某些text
进行HtmlEncode
,如下所示:
I am using the following method to HtmlEncode
some text
that it's in Spanish
, like this:
string word = "configuración";
string encodedWord = System.Net.WebUtility.HtmlEncode(word);
输出是预期的:
configuración
但是! ó
文本表示带有小写字母的拉丁文小写字母"o"的 HTML实体编号.
But! the ó
text represents the HTML entity number for a latin small letter "o" with acute.
但是,我想知道是否有一种方法-使用我不知道的内置函数,库等-显示HTML实体编号的 HTML实体名称并且还支持其他字符(例如通用解决方案).
However, I want to know if there is a way - using a built-in function which I don't know, library, etc - to show the HTML entity name of the HTML entity number and also support other characters (like a generic solution).
到目前为止,我一直尝试检查HTML实体表(Google搜寻时有很多,但我使用了这个表: http://www.ascii.cl/htmlcodes.htm ),然后创建了一个自定义method
,通过进行一些映射来替换单词中所需的string
.
What I've tried so far is to check for a HTML entities table (there were many when Googling but I used this one: http://www.ascii.cl/htmlcodes.htm) then created a custom method
for replacing the needed string
from the word by doing some mapping.
因此,如果单词包含ó
,则匹配的文本将被替换为 HTML实体名称,即oacute;
,但这确实很痛苦,因为有很多情况/场景.
So, if the word contains ó
then the matching text will be replaced to it's HTML entity name which is oacute;
but it is really painful since there are plenty of cases/scenarios.
最后,所需的输出将是:
Finally, the desired output will be:
configuración
推荐答案
HtmlEncode(word);仅编码 ISO 8859-1(Latin-1).这意味着您的输入需要按照ISO 8859-1进行编码. ó不在iso标准中,您可以尝试使用AntiXss编码器:
HtmlEncode(word); does only encode ISO 8859-1 (Latin-1). Which means your input needs to be encoded in ISO 8859-1. The ó is not in the iso standard, you can try to use the AntiXss encoder:
Microsoft.Security.Application.AntiXss.HtmlEncode("ó");
or Microsoft.Security.Application.Encoder.HtmlEncode("ó");
这篇关于带有HTML实体名称的HtmlEncode,可以吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!