/**
* 在str1中从start位置开始查找str2到end位置结束, 返回str2在str1的起始位置, -1表示查找失败
*/
public static int strstr(byte[] str1, byte[] str2, int start, int end)
{
int index1 = start;
int index2 = 0;
if(str2!=null)
{
while(index1<str1.length && index1<end)
{
int dsite = 0;
while(str1[index1+dsite]==str2[index2+dsite]) {
if(index2+dsite+1>=str2.length)
return index1;
dsite++;
if(index1+dsite>=str1.length || index2+dsite>=str2.length)
break;
}
index1++;
}
return -1;
}
else
return index1;
}