当前位置: 移动技术网 > IT编程>开发语言>Java > Java中替换HTML标签的方法代码

Java中替换HTML标签的方法代码

2019年07月22日  | 移动技术网IT编程  | 我要评论
1、替换html标签 复制代码 代码如下:replaceall("\\&[a-za-z]{0,9};", "").replaceall("<[^>]*>

1、替换html标签

复制代码 代码如下:

replaceall("\\&[a-za-z]{0,9};", "").replaceall("<[^>]*>", "\n\t")

源码如下:

复制代码 代码如下:

/**
 * 字符串替换
 */
package com.you.model;

/**
 * html标签替换
 * @author yhd
 * @version
 */
public class strreplace {

 /**
  * @param args
  */
 public static void main(string[] args)
 {
  string str = " <table border='1' cellpadding='1' cellspacing='1'><tr><th rowspan='2'>序号</th><th colspan='2'>李四</th><th>赵六</th></tr><table>";
  /**
   * 替换html标签
   */
  string substr = str.replaceall("\\&[a-za-z]{0,9};", "").replaceall("<[^>]*>", "\n\t");
  /**
   * 打印替换后的字符串
   */
  system.out.println("打印替换后的字符串:" + substr);
 }

}

2、运行结果如下

打印替换后的字符串:    
    序号 

    李四 

    赵六 

如您对本文有疑问或者有任何想说的,请 点击进行留言回复,万千网友为您解惑!

相关文章:

验证码:
移动技术网