Skip to content

Instantly share code, notes, and snippets.

@optimho
Created January 10, 2022 21:17
Show Gist options
  • Select an option

  • Save optimho/7150cc77dce74becb7ceaad48f3fb5ba to your computer and use it in GitHub Desktop.

Select an option

Save optimho/7150cc77dce74becb7ceaad48f3fb5ba to your computer and use it in GitHub Desktop.
You can extent a library function in Kotlin
fun main(args: Array<String>) {
val name="michael du Plessis"
println(name.initials())
}
fun String.initials():String{
val values:List<String> =this.split(' ')
val firstLetter:String = values[0].substring(0,1)
val lastLetter:String = values[1].substring(0,1)
return ("$firstLetter$lastLetter")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment