compareTo

open operator override fun compareTo(other: ByteString): Int(source)

Compares a byte sequence wrapped by this byte string to a byte sequence wrapped by other in lexicographical order. Byte values are compared as unsigned integers.

The behavior is similar to String.compareTo.

Parameters

other

the byte string to compare this string to.

Samples

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

fun main() { 
   //sampleStart 
   assertTrue(ByteString(1, 2, 3) == ByteString(1, 2, 3))
assertTrue(ByteString(1, 2, 3) <= ByteString(1, 2, 3))
assertTrue(ByteString(1, 2, 3) >= ByteString(1, 2, 3))
assertTrue(ByteString(1, 2, 3) < ByteString(1, 3, 2))

// If byte strings have different length, their content compared up to the length of the shortest string,
// and if their content was the same, then the shortest string is considered "smaller"
assertTrue(ByteString() < ByteString(1, 2, 3))
assertTrue(ByteString(1, 2, 3) > ByteString(1))
assertTrue(ByteString(1, 2, 3) < ByteString(1, 3))
assertTrue(ByteString(1, 2, 3) > ByteString(1, 1, 1, 1)) 
   //sampleEnd
}