encodeToByteString

Encodes a string into a byte sequence using UTF8-encoding and wraps it into a byte string.

Samples

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

fun main() { 
   //sampleStart 
   val helloAsByteString = "hello".encodeToByteString()
assertEquals(
    ByteString(
        'h'.code.toByte(),
        'e'.code.toByte(),
        'l'.code.toByte(),
        'l'.code.toByte(),
        'o'.code.toByte()
    ), helloAsByteString
)
assertEquals("hello", helloAsByteString.decodeToString()) 
   //sampleEnd
}

Encodes a string into a byte string using charset.

Parameters

charset

the encoding.