Egor0702
Egor0702

Reputation: 15

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

Upvotes: 0

Views: 320

Answers (1)

lukas.j
lukas.j

Reputation: 7173

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

Upvotes: 1

Related Questions