Skip to content

Instantly share code, notes, and snippets.

@ajaypro
Created June 13, 2020 12:22
Show Gist options
  • Save ajaypro/e844a3110d3848038d1136d159a18e15 to your computer and use it in GitHub Desktop.
Save ajaypro/e844a3110d3848038d1136d159a18e15 to your computer and use it in GitHub Desktop.
sample of substringAfter method
private const val FILE_PATH = "/storage/emulated/0/DCIM/Gallery/erwfwet285d9cesdferqwrsdfsg7e3259f.mp4"
fun main() {
val extension = FILE_PATH.substringAfter(delimiter = ".", missingDelimiterValue = "Extension Not found")
println("File extension -> $extension")
}
// Output
File extension -> mp4
Explanation: the above code successfully give you the mp4 extension name of the file.
But if we change the delimiter value to something which does not exist inside the source string
then the missingDelimiterValue will be returned which is Extension Not Found.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment