如我有个字符串为如下:
String ww ="<span class="content"><p align="center"><font size="2"><img height="294" width="526" alt="" src="/picstrue/1/Image/1162859037733.JPG" /></font></p>
<div><font size="2">&nbsp;&nbsp;&nbsp; 吃饭随风倒随风倒封调所附毒素发毒素发大毒素发毒素发大撒。</span></font></div><p align="center"><font size="2"><img height="257" width="501" alt="" src="/picstrue/1/Image/1162859065734.JPG" /></font></p>
<div><font size="2">&nbsp;&nbsp;&nbsp; 错的梵蒂冈梵蒂冈梵蒂冈发豆腐干梵蒂冈梵蒂冈梵蒂冈梵蒂冈梵蒂冈梵蒂冈豆腐干梵蒂冈。</font></div><div><font size="2">&nbsp;&nbsp;&nbsp; 大幅度的反对法撒扶绥大幅度撒发毒素发毒素发。</span>毒素发毒素发大撒再一次掀起交流会的高潮。</font></div>    </span>"我如何通过java把那些html标识符去掉,只得到我想要的汉字(如下那样)?String ww = " 吃饭随风倒随风倒封调所附毒素发毒素发大毒素发毒素发大撒。 错的梵蒂冈梵蒂冈梵蒂冈发豆腐干梵蒂冈梵蒂冈梵蒂冈梵蒂冈梵蒂冈梵蒂冈豆腐干梵蒂冈。大幅度的反对法撒扶绥大幅度撒发毒素发毒素发。毒素发毒素发大撒再一次掀起交流会的高潮"谢谢,小弟初学,在线等

解决方案 »

  1.   

    呵呵,你的String ww是错的.呵呵.这么多双引号啊.哈哈
    当然是一个一个字符看了哦.当遇到"<"后开始不输出,遇到">"后开始输出.
    例如:
        String ww="<p align='center'>错的梵蒂冈梵冈发豆腐干梵蒂冈梵蒂冈梵蒂冈梵</p>";
        char[] c=ww.toCharArray();
        boolean outable=true;
        StringBuffer sb=new StringBuffer();
        for(int i=0;i<c.length;i++)
        {
          if(c[i]=='<') outable=false;
          if(c[i]=='>') outable=true;
          if(outable) sb.append(c[i]);
        }
        System.out.println(sb.toString());
      

  2.   

    public static void main(String[] args) {
            // TODO Auto-generated method stub
            String ww ="<span class=\"content\"><p align=\"center\"><font size=\"2\">" +
                    "<img height=\"294\" width=\"526\" alt=\"\" src=\"/picstrue/1/Image/1162859037733.JPG\" /></font></p>"+
                    "<div><font size=\"2\">&nbsp;&nbsp;&nbsp; 吃饭随风倒随风倒封调所附毒素发毒素发大毒素发毒素发大撒。</span></font>" +
                    "</div><p align=\"center\"><font size=\"2\"><img height=\"257\" width=\"501\" alt=\"\" src=\"/picstrue/1/Image/1162859065734.JPG\" />" +
                    "</font></p><div><font size=\"2\">&nbsp;&nbsp;&nbsp; 错的梵蒂冈梵蒂冈梵蒂冈发豆腐干梵蒂冈梵蒂冈梵蒂冈梵蒂冈梵蒂冈梵蒂冈豆腐干梵蒂冈。</font></div><div><font size=\"2\">" +
                    "&nbsp;&nbsp;&nbsp; 大幅度的反对法撒扶绥大幅度撒发毒素发毒素发。</span>毒素发毒素发大撒再一次掀起交流会的高潮。</font></div>    </span>";
            Pattern p = Pattern.compile("<[^>]*>");
            Matcher m = p.matcher(ww);
            String res = m.replaceAll("");
            System.out.println(res);
        }
    输出结果如下:
    =======================================================================
    &nbsp;&nbsp;&nbsp; 吃饭随风倒随风倒封调所附毒素发毒素发大毒素发毒素发大撒。&nbsp;&nbsp;&nbsp; 错的梵蒂冈梵蒂冈梵蒂冈发豆腐干梵蒂冈梵蒂冈梵蒂冈梵蒂冈梵蒂冈梵蒂冈豆腐干梵蒂冈。&nbsp;&nbsp;&nbsp; 大幅度的反对法撒扶绥大幅度撒发毒素发毒素发。毒素发毒素发大撒再一次掀起交流会的高潮。    
    =======================================================================
      

  3.   

    String s = ww.replaceAll("[^。,\u4e00-\u9fa5]", "");