我已经尝试了一段时间了,我有一个字符串,其中包含了很多HTML标记,它以某种编码形式存在,比如& lt;和& gt;(没有空格)在字符串之间。有人能帮我移除那些标签吗?这样我就可以得到一个简单的字符串了吗?
发布于 2021-10-18 18:25:08
这里是我的解决方案,如果使用颤振网页或不能导入解析器,因为任何原因,它是可配置的。
String formatHtmlString(String string) {
return string
.replaceAll("\n\n", "<p>") // Paragraphs
.replaceAll("\n", "<br>") // Line Breaks
.replaceAll("\"", """) // Quote Marks
.replaceAll("'", "'") // Apostrophe
.replaceAll(">", "<") // Less-than Comparator (Strip Tags)
.replaceAll("<", ">") // Greater-than Comparator (Strip Tags)
.trim(); // Whitespace
}https://stackoverflow.com/questions/51593790
复制相似问题