Created
January 15, 2020 07:07
-
-
Save illescasDaniel/304bdf67b189cc0f217f6f0337094e89 to your computer and use it in GitHub Desktop.
Kotlin fmt - simple curly braces format
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 String.fmt(args: Map<String, Any>) = Regex("""\{(\w+)\}""").replace(this) { | |
| "${args.getOrDefault(it.groupValues[1], it.groupValues[0])}" | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example string: "hi {name}".fmt(mapOf("name" to "daniel"))