lastIndexOf
Returns the index within this char sequence of the last occurrence of the specified byte, starting from the specified startIndex. If the byte not found, -1
is returned.
Behavior of this method is compatible with CharSequence.lastIndexOf.
Parameters
the value to search for.
the index (inclusive) starting from which the byte should be searched.
Samples
import kotlinx.io.bytestring.*
import kotlin.test.*
fun main() {
//sampleStart
val string = ByteString(1, 2, 3, 2, 1)
assertEquals(3, string.lastIndexOf(2))
assertEquals(-1, string.lastIndexOf(2, startIndex = 4))
assertEquals(-1, string.indexOf(0))
//sampleEnd
}
Returns the index within this char sequence of the last occurrence of the specified byteString, starting from the specified startIndex. If the byteString not found, -1
is returned.
Behavior of this method is compatible with CharSequence.lastIndexOf.
Parameters
the value to search for.
the index (inclusive) starting from which the byteString should be searched.
Samples
import kotlinx.io.bytestring.*
import kotlin.test.*
fun main() {
//sampleStart
val string = ByteString(1, 2, 3, 4, 1, 3, 4)
assertEquals(5, string.lastIndexOf(ByteString(3, 4)))
assertEquals(-1, string.lastIndexOf(ByteString(1, 2), startIndex = 3))
assertEquals(0, string.lastIndexOf(ByteString(1, 2, 3)))
assertEquals(-1, string.lastIndexOf(ByteString(1, 3, 4, 5)))
assertEquals(string.size, string.lastIndexOf(ByteString(/* empty byte string */)))
//sampleEnd
}
Returns the index within this char sequence of the last occurrence of the specified byteArray, starting from the specified startIndex. If the byteArray not found, -1
is returned.
Behavior of this method is compatible with CharSequence.lastIndexOf.
Parameters
the value to search for.
the index (inclusive) starting from which the byteArray should be searched.
Samples
import kotlinx.io.bytestring.*
import kotlin.test.*
fun main() {
//sampleStart
val string = ByteString(1, 2, 3, 4, 1, 3, 4)
assertEquals(5, string.lastIndexOf(byteArrayOf(3, 4)))
assertEquals(-1, string.lastIndexOf(byteArrayOf(1, 2), startIndex = 3))
assertEquals(0, string.lastIndexOf(byteArrayOf(1, 2, 3)))
assertEquals(-1, string.lastIndexOf(byteArrayOf(1, 3, 4, 5)))
assertEquals(string.size, string.lastIndexOf(byteArrayOf(/* empty byte array */)))
//sampleEnd
}