gpt4 book ai didi

google-apps-script - 如何解码 HTML 实体

转载 作者:行者123 更新时间:2023-12-03 07:30:16 24 4
gpt4 key购买 nike

我有带有 HTML 实体的字符串变量:

var str = '一些文本&文本';

我想将其转换(解码)为原始字符:

一些文字和文字

JavaScript 没有内置函数来实现想要的结果。我无法使用 jQuery 或 DOM 对象,因为我需要它在 Google Apps 脚本中工作。

我怎样才能以简单的方式做到这一点?

最佳答案

您可以使用内置 Xml 服务 ( reference ):

var str = 'Some text & text';
var decode = XmlService.parse('<d>' + str + '</d>');
var strDecoded = decode.getRootElement().getText();

或者您可以使用内置的 E4X XML 类。

var str = 'Some text &#x26; text';
var decode = new XML('<d>' + str + '</d>');
var strDecoded = decode.toString();

关于google-apps-script - 如何解码 HTML 实体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11366021/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com