codePointBefore

Returns the character (Unicode code point) before the specified index.

inline fun String.codePointBefore(index: Int): Int(source)
val text = "Hello, world!"
val index = 12                     // position of the second 'l' in "world"
val codePoint = text.codePointBefore(index)

println("Code point before index $index: U+${codePoint.toString(16).uppercase()}")
println("Character: ${codePoint.toChar()}")

Source