您的位置:首页 > 其它

求子串位置的定位函数

2014-05-21 10:20 225 查看
package test1;
public class test2 {
public static int index(char[] s,char[] t,int pos) {
int i=pos;
int j=0;
while (i<s.length && j<t.length) {
if (s[i]==t[j]) {
++i;
++j;
}
else {
i=i-j+1;
j=0;
}
}
if (j>=t.length) {
return i-t.length;
}
else return 0;
}
public static void main(String[] args) {
String S="asdffwrewrew";
char[] s1=S.toCharArray();
String T="ew";
char[] t1=T.toCharArray();
System.out.println(index(s1, t1, 0));
}
}


  
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐