修车朋友妈妈戒赌吧:java 去html标签,去除字符串中的空格,回车,换行符,制表符 - 菜菜 - Java...

来源:百度文库 编辑:中财网 时间:2024/04/29 00:12:18
 public static String getonerow(String allLine,String myfind)
    {
           
              Pattern pattern = Pattern.compile("
.*?
");        
             Matcher  matcher = pattern.matcher(allLine);
            while(matcher.find()) {
                String  myval = matcher.group();
                int npos=myval.indexOf(myfind);
                if(npos>=0)
                {
                    npos = myval.indexOf("");
                    if(npos>0)
                    {
                         String content = myval.substring(npos,myval.length());
                         content=content.replaceAll("]+>","");   //剔出了的标签
                         content=content.replace(" ","");
                         content=content.replace(".","");
                         content=content.replace("\"","‘");
                         content=content.replace("'","‘");
                         content=content.replaceAll("\\s*|\t|\r|\n","");//去除字符串中的空格,回车,换行符,制表符
                         return content;
                    }
                }
            }
            return "";
   
    }

这仅仅是压缩html的一个模糊概念,以上仅供参考