如何删除String的HTML元素? [英] How to remove HTML element of String?
本文介绍了如何删除String的HTML元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想删除Java中的HTML字符串。
< hr>< b>< strong>任务详情< / strong>< / b>< hr>< b>创建日期:< / b> 01/06/2014 07:55 pm<br><b>修改日期:< / b> 01/06/2014 07:55 pm<br><b>已分配给:< / b>管理员< br>< b>创建者:< / b>管理员< br>< b>状态:< / b>未开始< br>< b>说明:< / b>测试说明< br> ;.
以上是我的字符串,我想删除HTML标记。
解决方案
也许这会起作用:
String noHTMLString = htmlString.replaceAll(\\<。*?>,);
它使用正则表达式去除字符串中的所有HTML标签。
更具体地说,它从字符串中删除所有类似XML的标记。所以< 1234>即使不是有效的HTML标签也会被移除。但它对大多数意图和purpouses有好处。
希望这会有帮助。
这实际上很简单, a href =http://jsoup.org/ =nofollow> Jsoup。
public static String html2text(String html){
return Jsoup.parse(html).text();
}
I want to remove HTML of string in Java.
<hr><b><strong>Task Details</strong></b><hr><b>Date Created: </b> 01/06/2014 07:55pm<br><b>Date Modified: </b> 01/06/2014 07:55pm<br><b>Assigned to: </b> Administrator<br><b>Created By: </b> Administrator<br><b>Status: </b> Not Started<br><b>Description: </b> Test Description<br>.
Above is my string and I want to remove HTML tags.
解决方案
Maybe this will work:
String noHTMLString = htmlString.replaceAll("\\<.*?>","");
It uses regular expressions to remove all HTML tags in a string.
More specifically, it removes all XML like tags from a string. So <1234> will be removed even though it is not a valid HTML tag. But its good for most intents and purpouses.
Hope this helps.
This is actually dead simple with Jsoup.
public static String html2text(String html) {
return Jsoup.parse(html).text();
}
这篇关于如何删除String的HTML元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文