anyone know of a good way to check if a String con...
# multiplatform
n
anyone know of a good way to check if a String contains ONLY ASCII characters in an
ios
target
actual
?
aside from comparing the int value of each character to the ascii charset of utf-8
i
You could get clever and write it to a byte array then see if the int values are the same at each character.
n
Yeah, that's what I ended up doing. I haven't tested it yet, though
Copy code
actual fun String.isAscii(): Boolean = this.toCharArray().any { c -> c.toInt() !in 0..127 }
i
Well that ends up being a lot of searching. I mean take the char array and walk it casting each char to a byte and check if the int values of each match