On an Android project with both Kotlin and java, I want to use the Kotlin functions substringBeforeLast(delimiter)
and substringAfterLast(delimiter)
in some java files.
So i thought of using extensions. I did the following which works,
fun String.getStringAfterLast(): String{
return this.substringAfterLast(".")
}
however i was thinking of passing the delimiter as a parameter, but it gives me an error when trying to use in java "remove 2nd argument..."
fun String.getStringBeforeLast(delimiter: String): String{
return this.substringBeforeLast(delimiter)
}
Is the approach correct ? Can it be done ?