Created
January 10, 2022 21:17
-
-
Save optimho/7150cc77dce74becb7ceaad48f3fb5ba to your computer and use it in GitHub Desktop.
You can extent a library function in Kotlin
This file contains hidden or 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
| 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