如:“I1I2I3”这个字符串,有个子字符串“I1I3”,这个用contains判断是不存在在那个字符串中的
有什么方法可以判断I1I3是存在那个字符串中的。既只要I1I2I3这个字符串只要有I1I3就可以了,

解决方案 »

  1.   

    把字串逐个比较呀:    public static void main(String[] args) {
            System.out.println(charContains("I1I2I3", "I1I3"));
        }    public static boolean charContains(String s, String sub) {
            if (s == null || sub == null)
                return false;        for (int i = 0; i < sub.length(); i++) {
                boolean contains = false;
                char c = sub.charAt(i);
                for (int j = 0; j < s.length(); j++) {
                    if (c == s.charAt(j)) {
                        contains = true;
                        break;
                    }
                }
                if (!contains)
                    return false;
            }        return true;
        }
      

  2.   

    既只要I1I2I3这个字符串只要有I1I3就可以了,那 I1I2I3 只要有 I 可以不?
      

  3.   

    个人认为比较简单的做法:
    public static void main(String[] args) {
    String str="I1I2I3";

    String str1=str.replaceAll("I1I3", "");
    System.out.print((!str.equals(str1))? "含有此字符串!":"不含有此字符串!");}
      

  4.   

    :“I1I2I3”这个字符串,有个子字符串“I1I3”???怎么可能啊?
      

  5.   

    难道是这个? public static void main(String[] args) {
    String  str = "I11I4I31I3I5I3";

    String regex = "I(?=[1|3]{1})";

    Pattern pat= Pattern.compile(regex);

    Matcher mat = pat.matcher(str);

    if(mat.find()){

    System.out.println(" It contant");

    }else{

    System.out.println("It  dose not contant");

    } }