[SOLVED] Analog of Java substring() and lastIndexOf() on Kotlin


In java, this code worked:

String tempDir = c.getString(0);
tempDir = tempDir.substring(0, tempDir.lastIndexOf("/"));

But I can’t write this code in kotlin:

var string: String = c.getString(0)
var sequence: CharSequence = tempDir.subSequence(0, string.length)
var indexLast = sequence.lastIndexOf("/",0,false) // error


val tempDir = c.getString(0).substringBeforeLast("/")

Answered By – lukas.j

Answer Checked By – Jay B. (BugsFixing Admin)

Leave a Reply

Your email address will not be published. Required fields are marked *