class StringSub { public static void main(String[] args) { String str = "asdfqwers"; String s = "wer"; System.out.println(StringFind(str, s)); } static int StringFind(String str, String s) { char[] strChar = str.toCharArray(); char[] sChar = s.toCharArray(); int j = 0; for (int i = 0; i < strChar.length; i++) { if (sChar[j] == strChar[i]) { if (j < sChar.length - 1) { j++; continue; } else { return (i - sChar.length + 1); } } else { continue; } } return -1; } }
从一个字符串查找一个子字符串
最新推荐文章于 2022-06-05 16:39:34 发布