1、简单模式匹配
public static int findIndex(String s, String t) {
int index = 0;
char[] sChars = s.toCharArray();
char[] tChars = t.toCharArray();
int i = 0, j = 0;
while (i < sChars.length && j < t.length()) {
if(sChars[i] == tChars[j]) {
i++;
j++;
} else {
i = i - j + 1;
j = 0;
}
}
if(j == tChars.length) {
index = i - j;
} else {
index = -1;
}
return index;
} public static int fin