gpt4 book ai didi

java - 用字符实体替换 HTML 代码

转载 作者:太空宇宙 更新时间:2023-11-04 15:08:54 25 4
gpt4 key购买 nike

我有包含 HTML 代码的字符串,如 ”’ 等。我想将其替换为相应的实体集,如 ( & ') 在 Java 中。我尝试过以下代码。

<小时/>
if (StringUtils.isNotBlank(string)) {
string = StringEscapeUtils.unescapeXml(string);
string = StringEscapeUtils.unescapeHtml(string);
string = string.replaceAll("<.*?>", "");
string = string.trim();
}
<小时/>

输入字符串:

brief is a tie side, string style embellished with shimmering silver sequins. 
Dangling gunmetal chain tassels decorate the end of each hip tie. Model&amp;apos;s
Measurements Height 5&amp;apos;10.5&amp;quot; Hips 36&amp;#148; Waist 23.5&amp;#148;
Model wears size 2

我得到以下包含 BadEncoding 的输出:

brief is a tie side, string style embellished with shimmering silver 
sequins. Dangling gunmetal chain tassels decorate the end of each hip tie. Model's
Measurements Height 5'10.5" Hips 36<94> Waist 23.5<94> Bust 35<94> Model wears size 2

所需输出:

brief is a tie side, string style embellished with shimmering silver sequins. 
Dangling gunmetal chain tassels decorate the end of each hip tie. Model's
Measurements Height 5'10.5" Hips 36" Waist 23.5" Bust 35" Model wears size 2

请提出建议。

最佳答案

如果您关心的只是数字字符转义,则该数字是一个字符编号,只需将其转换为 int,然后再转换为 char 即可相当直接地使用。请参阅http://www.w3.org/International/questions/qa-escapes

关于java - 用字符实体替换 HTML 代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21594726/

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