扩展 HTML 字符串以具有命名字符实体
.NET 类库中是否有一种方法可以对字符串进行编码,以便将命名实体存在的任何字符替换为使用该命名实体? HttpUtility.HtmlEncode 似乎没有帮助:
// Result is "$", would like "€" instead
var encoded = HttpUtility.HtmlEncode("€");
Is there a way in the .NET class library to encode a string so that any character for which a named entity exists is replaced to use this named entity? HttpUtility.HtmlEncode doesn't appear to help:
// Result is "$", would like "€" instead
var encoded = HttpUtility.HtmlEncode("€");
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您必须亲自动手,从规范中获取命名实体的规范列表,然后创建一个循环,对于每个命名实体,只需用相应的实体引用替换该字符的每次出现。
I think you would have to get your hands dirty and just grab the canonical list of named entities from the specification and then create a loop that, for every named entity, simply replaces every occurrence of that character with the corresponding entity reference.