自定义的HTMLEncode与HTML实体名称,这可能吗? [英] Custom HtmlEncode with HTML entity name, is it possible?

查看:471
本文介绍了自定义的HTMLEncode与HTML实体名称,这可能吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用下面的方法的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

但是!在&放大器;#243; 文本表示一个拉丁小字母o急性的HTML实体号

But! the ó text represents the HTML entity number for a latin small letter o with acute.

不过,我想知道是否有一个快速的方法(内置函数,我不知道,图书馆,已实现的功能等),以显示对于带O的拉丁小写字母的HTML实体号的HTML实体名称急,还支持许多其他字符,因为我没能找到一个很好的解决方案。

However, I want to know if there is a fast way (built-in function which I don't know, library, an already implemented function, etc) to show the HTML entity name for the HTML entity number for a latin small letter with o acute and also support many other characters since I wasn't able to find a good solution for this.

PS:我已经试过是检查一个HTML实体表(有许多在那里进行搜索时,但我使用这样的:的 http://www.ascii.cl/htmlcodes.htm ),并创建自定义的通过做一些映射替换字符串。因此,如果这个词包含&放大器;#243; 然后取代它,以它的是HTML实体名称 oacute; ,但真的很痛苦,因为有大量的案件。最后,所需的输出将是:

P.S: What I've tried is to check for a HTML entities table (there are many over there when searching but I am using this: http://www.ascii.cl/htmlcodes.htm) and create a custom method for replacing the string by doing some mapping. So, if the word contains ó then replace it to it's HTML entity name which is oacute; but it is really painful since there are plenty of cases. Finally, the desired output will be:

configuración

在此先感谢

推荐答案

的HTMLEncode(字)。只做编码 ISO 8859-1(Latin-1的)。这意味着你的输入需要在ISO 8859-1进行编码。该O不再是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("ó");

这篇关于自定义的HTMLEncode与HTML实体名称,这可能吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆