如果第一个字符匹配,则代码返回true。您需要将第一个字符串的所有字符包含在第二个字符串的子字符串中。
编辑:
我的原始代码是错误的。这是正确的代码:
public static boolean subString(String str1, String str2) { String s1 = str1.toLowerCase(); String s2 = str2.toLowerCase(); for (int offset = 0; offset <= s2.length() - s1.length(); offset++) { int i = 0; for (; i < s1.length(); i++){ if(s1.charAt(i) != s2.charAt(i+offset)) { break; } } // found a substring that starts at the current offset if (i == s1.length()) return true; } return false; }
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)