我试着用StringEscapeUtils.unescapeHtml4(),替换HTML5的符号,但是我仍然有很多符号还没有被替换,比如“replace”、“&”。您推荐使用什么?
发布于 2016-01-21 15:22:42
 和&不是实体。 和&是实体。如果您的字符串确实丢失了它们上的;,这就是它们没有被解码的原因。
我只是检查了一下(为了彻底起见!),StringEscapeUtils.unescapeHtml4 做了正确的解码 和&。
正确的修复是修复任何给您的不完整实体的字符串。
您可以解决这个问题,也可以在使用 和&之后使用String#replace将StringEscapeUtils.unescapeHtml4转换为\u00A0和&。
// Ugly, technically-incorrect workaround (but we do these things sometimes)
String result =
StringEscapeUtils.unescapeHtml4(sourceString)
.replace(" ", "\u00A0")
.replace("&", "&");...but这是不正确的,因为这些不是实体。最好把绳子改一下。
https://stackoverflow.com/questions/34927373
复制相似问题