将HTML实体解码为纯文本 [英] Decode HTML entities into plain text

查看:83
本文介绍了将HTML实体解码为纯文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个字符串,其中包含 HTML实体(例如&加号; -加号减号).

I have a string that includes HTML entities (e.g. ± - the plus minus symbol).

如何获取带有已解码为纯文本的HTML实体的字符串?

How can I get the string with those HTML entities decoded into plain text?

示例:

 Input          |  Output
----------------+-------------
±        |    ±
Ben & Jerry | Ben&Jerry

推荐答案

您可以创建一个 HTMLDocument 对象,将HTML存储在其中,并从中获取其文本版本:

You could create an HTMLDocument object, store the HTML in it, and get the text version of it out of it:

Function HtmlDecode(str)
    Dim dom

    Set dom = CreateObject("htmlfile")
    dom.Open
    dom.Write str
    dom.Close
    HtmlDecode = dom.body.innerText
End Function

decoded = HtmlDecode("±")   ' =  "±"

这篇关于将HTML实体解码为纯文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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