substring

fun substring(startIndex: Int, endIndex: Int = size): ByteString(source)

Returns a new byte string wrapping a subsequence of bytes wrapped by this byte string starting from startIndex and ending at endIndex.

Parameters

startIndex

the start index (inclusive) of a subsequence to copy.

endIndex

the end index (exclusive) of a subsequence to copy, size be default.

Throws

when startIndex or endIndex is out of range of byte string indices.

when startIndex > endIndex.

Samples

import kotlinx.io.bytestring.*
import kotlin.test.*

fun main() { 
   //sampleStart 
   val string = ByteString(1, 2, 3, 4, 5)
assertEquals(ByteString(1, 2, 3), string.substring(startIndex = 0, endIndex = 3))
assertEquals(ByteString(3, 4, 5), string.substring(startIndex = 2))
assertEquals(ByteString(2, 3, 4), string.substring(startIndex = 1, endIndex = 4)) 
   //sampleEnd
}