https://kotlinlang.org logo
Title
k

Konstantin Petrukhnov

03/19/2018, 9:36 AM
I have hex string (bytes), and i need convert to normal string. Is it something like data.toByteArray().contentToString() ?
m

msink

03/19/2018, 10:38 AM
From INTEROP.md:
val path = getenv("PATH")?.toKString() ?: ""
k

Konstantin Petrukhnov

03/19/2018, 10:43 AM
@msink your answer leaked to other thread 😉
k

Konstantin Petrukhnov

03/19/2018, 1:08 PM
Do you mean, that there is no available implementation or library for that?
o

olonho

03/19/2018, 1:22 PM
ByteArray.stringFromUtf8
does what you ask for
k

Konstantin Petrukhnov

03/19/2018, 1:37 PM
hm... this method is not available to me
o

olonho

03/19/2018, 1:43 PM
import
kotlin.text
package
k

Konstantin Petrukhnov

03/19/2018, 1:51 PM
I have gradle project with compile "org.jetbrains.kotlin:kotlin-stdlib:1.2.30". I could use StringBuilder and ByteArray in project. This method is not available. Even if i explicitly add "import kotlin.text.*" in source file
i don't see any method in these classes that have "utf" in it
o

olonho

03/19/2018, 2:03 PM
this method is Kotlin/Native specific
k

Konstantin Petrukhnov

03/19/2018, 2:06 PM
Do I understood correctly, that there is no generic method, that could be used in "common" kotlin code, that will be them compiled to each platform?
I want to do something like "String(myByteArray)", which works on jvm, but not in iOS
o

olonho

03/19/2018, 2:08 PM
yes, but nobody prevents you from writing one using MPP
k

Konstantin Petrukhnov

03/19/2018, 2:15 PM
ok, thx 🙂
d

Deactivated User

03/19/2018, 2:33 PM
@Konstantin Petrukhnov if you need a MPP function for that, to use before String<->ByteArray conversions are avaialble for MPP, you can use (copy-paste and adjust as needed) this one in the meantime: https://github.com/soywiz/start-ktor-io-proposal/blob/master/src/io/ktor/start/util/charset.kt https://github.com/soywiz/start-ktor-io-proposal/blob/master/src/io/ktor/start/util/baos.kt
p

passsy

03/20/2018, 5:33 PM
Ran into that as well. Is there a roadmap which functions will be implemented for iOS in the future? Can I expect to get all functions on iOS which are currently supported by jvm?