Skip to content

Instantly share code, notes, and snippets.

@illescasDaniel
Created January 15, 2020 07:07
Show Gist options
  • Select an option

  • Save illescasDaniel/304bdf67b189cc0f217f6f0337094e89 to your computer and use it in GitHub Desktop.

Select an option

Save illescasDaniel/304bdf67b189cc0f217f6f0337094e89 to your computer and use it in GitHub Desktop.
Kotlin fmt - simple curly braces format
fun String.fmt(args: Map<String, Any>) = Regex("""\{(\w+)\}""").replace(this) {
"${args.getOrDefault(it.groupValues[1], it.groupValues[0])}"
}
@illescasDaniel
Copy link
Copy Markdown
Author

Example string: "hi {name}".fmt(mapOf("name" to "daniel"))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment