I have a string that is an email. I want to be able to get the domain part of the email no matter what the string/email is. Essentially I'm wanting to get hold of the characters after the @ part of the string. For example, for [email protected], I'm after the kotlin.com part.
val emailString = "[email protected]"
While there's nothing wrong with the accepted answer the Kotlin standard library is worth exploring as it contains nice little methods like substringAfterLast
which would shorten the example to this
val string = "[email protected]"
val domain: String? = string.substringAfterLast("@")