public static int findBytes ( byte [ ] utf , int start , int end , byte [ ] b ) { int matchEnd = end - b . length ; for ( int i = start ; i <= matchEnd ; i ++ ) { boolean matched = true ; for ( int j = 0 ; j < b . length ; j ++ ) { if ( utf [ i + j ] != b [ j ] ) { matched = false ; break ; } } if ( matched ) { return i ; } } return - 1 ; }
Find the first occurrence of the given bytes b in a UTF - 8 encoded string