decodeToString

Decodes content of a byte string into a string using UTF-8 encoding.

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
}

Decodes the content of a byte string to a string using given charset.

Parameters

charset

the charset to decode data into a string.