indexOf

fun ByteArray.indexOf(sub: ByteArray, fromIndex: Int = 0): Int

Returns the index of the first occurrence of the given byte sequence at or after fromIndex.

A negative fromIndex is treated as 0. When sub is empty, the result is fromIndex clamped into the range 0..size, matching the convention of String.indexOf with an empty argument. This function never throws.

Return

the index of the first match, or -1 if sub does not occur at or after fromIndex.

Parameters

sub

the byte sequence to search for.

fromIndex

the first index to consider, 0 by default.