当前位置: 移动技术网 > IT编程>开发语言>Java > Java 语言实现清除带 html 标签的内容方法

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

2019年07月22日  | 移动技术网IT编程  | 我要评论

实例如下:

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 标签的内容方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持移动技术网。

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网