Skip to content

Instantly share code, notes, and snippets.

@ajaypro
Created June 13, 2020 12:31
Show Gist options
  • Save ajaypro/221b7183412c3da79e37fcc5d50dffb7 to your computer and use it in GitHub Desktop.
Save ajaypro/221b7183412c3da79e37fcc5d50dffb7 to your computer and use it in GitHub Desktop.
Sample of kotlin code substringAfterLast()
private const val FILE_PATH = "/storage/emulated/0/DCIM/Gallery/.2394823usfdfh234uu9sd2333.mp4"
fun main() {
val fileExtension = FILE_PATH.substringAfterLast(delimiter = ".", missingDelimiterValue = "Extension Not found")
println("File extension -> $fileExtension")
}
// Output
File extension -> mp4
Explanation: the substringAfterLast method successfully gives the file extension
although the FILE_PATH contains two delimiter value well, that’s because the method
starts searching from the right-side of source string.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment