https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
c

Colby

12/05/2023, 4:54 PM
Is there a reason that
String.encodeToByteArray()
doesn't allow for choosing the desired encoding? It uses UTF-8 but I need ASCII
e

ephemient

12/05/2023, 4:58 PM
if your string only contains ASCII characters then UTF-8 is compatible. if your string isn't ASCII then how are you expecting to encode it to ASCII?
c

Colby

12/05/2023, 5:14 PM
You use some default value for the UTF-8 chars that aren't ASCII. I believe that's '?'.
d

Daniel Pitts

12/07/2023, 10:49 PM
There is
String.toByteArray
which takes an encoding. It looks like
encodeToByteArray()
just called
toByteArray(Charsets.UTF_8)
anyway.
e

ephemient

12/08/2023, 3:05 AM
only on JVM
d

Daniel Pitts

12/08/2023, 3:31 AM
Ah, didn't realize.
e

ephemient

12/08/2023, 3:44 AM
Charset and Locale only exists on JVM
2 Views