Skip to content

Instantly share code, notes, and snippets.

@ajaypro
Created June 13, 2020 12:28
Show Gist options
  • Save ajaypro/ff2952a03c13b6a5dba049c99a6d99ef to your computer and use it in GitHub Desktop.
Save ajaypro/ff2952a03c13b6a5dba049c99a6d99ef to your computer and use it in GitHub Desktop.
sample use of substringBefore method
private const val EMAIL = "[email protected]"
fun main() {
val username = MY_EMAIL.substringBefore(delimiter = "@", missingDelimiterValue = "Usernmae Not Found")
println("Username -> $username")
}
// Output
Username -> ajaydeepak07
Explanation: the above program returns the substring before the appearance of @ character.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment