java中怎麼判斷一個字符串在另外一個字符串中的方法

判斷一個A字符串是否在B字符串中的方法
String A ="aadfsd"
String B = "3443434weewweaadfsdfddffddf"
int Alen = A.length
int i=0;
byte[] a = A.toArray()
int j=0;
int Blen = B.length
byte[] b = B.toArray()
//偏移量
int c =3;
if(c<0||c>Blen - Alen ){
    return false;
}
while(--Alen){
   if(a[i++] != b[i++]){
      return false
   }
}

return true;
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章