Home > front end >  Kotlin #toCharArray giving wrong characters
Kotlin #toCharArray giving wrong characters

Time:05-08

I'm trying to loop through characters of a string. While doing so I found out that the #toCharArray function doesn't split special characters correctly. Here is my testing code:

val text = "\uD835\uDC9C"
text.toCharArray().forEach {
  println(it)
}

Is giving me the following response

?
?

So it seems like that it thinks that \uD835\uDC9C are 2 separate characters. But it should return only a single element

  • Related