源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

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

  • 时间:2020-02-07 06:49 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:Java中替换HTML标签的方法代码
1、替换HTML标签
[u]复制代码[/u] 代码如下:
replaceAll("\\&[a-zA-Z]{0,9};", "").replaceAll("<[^>]*>", "\n\t")
源码如下:
[u]复制代码[/u] 代码如下:
/**  * 字符串替换  */ 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、运行结果如下 打印替换后的字符串:         序号      李四      赵六 
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部