首页 > 开发 > Java > 正文

Java 语言实现清除带 html 标签的内容方法

2024-07-13 10:04:00
字体:
来源:转载
供稿:网友

实例如下:

public String stripHtml(String content) { // <p>段落替换为换行 content = content.replaceAll("<p .*?>", "/r/n"); // <br><br/>替换为换行 content = content.replaceAll("<br//s*/?>", "/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 标签的内容方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持VeVb武林网。


注:相关教程知识阅读请移步到JAVA教程频道。
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表