Created
June 13, 2020 12:31
-
-
Save ajaypro/221b7183412c3da79e37fcc5d50dffb7 to your computer and use it in GitHub Desktop.
Sample of kotlin code substringAfterLast()
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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