如何判断一个字符串中是否含有另一个字符串?
例如判断"<title>开发</title>"中是否含有"开发"该如何做?

解决方案 »

  1.   

    String s1=("<title>开发</title>");
    if(s1.indexOf("开发"))
        System.out.println("true");
      

  2.   

    楼上的用法不行
    sl.indexOf("开发");//返回一个整数,不能用整数当逻辑值。String s1=("<title>开发</title>");
    String ss;
    ss=s1.substring(sl.indexOf(">")+1,sl.lastIndexOf("<"));if(ss.equals("开发"))
        System.out.println("true");
      

  3.   

    可以用正则表达式进行判断,String.matches()~~~
    或者用String.indexOf(),如果返回-1,说明没有匹配,否则返回匹配的位置~~~
      

  4.   

    我晕,楼上的还真是复杂if(str.indexOf("CSDN")!=-1){
      system.out.println("存在");
    }