下面小编就为大家带来一篇Java 语言实现清除带 html 标签的内容方法。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧
实例如下:
public String stripHtml(String content) { //段落替换为换行 content = content.replaceAll("
", "\r\n"); //
替换为换行 content = content.replaceAll("
", "\r\n"); // 去掉其它的<>之间的东西 content = content.replaceAll("\\<.*?>", ""); // 去掉空格 content = content.replaceAll(" ", ""); // 还原HTML // content = HTMLDecoder.decode(content); return content; } public static String delHtmlTag(String str){ String newstr = ""; newstr = str.replaceAll("<[.[^>]]*>",""); newstr = newstr.replaceAll(" ", ""); return newstr; }
以上就是Java 语言实现清除带 html 标签的内容方法的详细内容,更多请关注0133技术站其它相关文章!