First a quick definition 🙂
- Template – A string which may contain placeholders (example:”hello [name]”)
- Placeholder – A substring whitin square brackets (example: “name” in “hello [name]:).
- Properties map – A valid object with strings as values
I need to write a code that replace placeholders (along with brackets) with the matching values in the properties map.
example:
for the following properties map:
{
"name":"world",
"my":"beautiful",
"a":"[b]",
"b":"c",
"c":"my"
}
Expected results:
-
“hello name” -> “hello name”
-
“hello [name]” -> “hello world”
-
“[b]” -> “c”
-
“[a]” -> “c” (because [a]->[b]->[c])
-
“[[b]]” -> “my” (because [[b]]->[c]->my)
-
“hello [my] [name]” -> “hello beautiful world”
1 Answer