startsWith
Returns true if this byte string starts with the prefix specified by the byteArray.
Behavior of this method is compatible with CharSequence.startsWith.
Parameters
byteArray
the prefix to check for.
Samples
import kotlinx.io.bytestring.*
import kotlin.test.*
fun main() {
//sampleStart
val string = ByteString(1, 2, 3, 4, 5)
assertTrue(string.startsWith(byteArrayOf(1, 2, 3, 4, 5)))
assertTrue(string.startsWith(byteArrayOf(/* empty byte array */)))
assertTrue(string.startsWith(byteArrayOf(1, 2, 3)))
assertFalse(string.startsWith(byteArrayOf(1, 3, 4)))
assertFalse(string.startsWith(byteArrayOf(1, 2, 3, 4, 5, 6)))
//sampleEnd
}
Returns true if this byte string starts with the prefix specified by the byteString.
Behavior of this method is compatible with CharSequence.startsWith.
Parameters
byteString
the prefix to check for.
Samples
import kotlinx.io.bytestring.*
import kotlin.test.*
fun main() {
//sampleStart
val string = ByteString(1, 2, 3, 4, 5)
assertTrue(string.startsWith(string))
assertTrue(string.startsWith(ByteString(/* empty byte string */)))
assertTrue(string.startsWith(ByteString(1, 2, 3)))
assertFalse(string.startsWith(ByteString(1, 3, 4)))
assertFalse(string.startsWith(ByteString(1, 2, 3, 4, 5, 6)))
//sampleEnd
}