{"is-c3-clipboard-data":true,"type":"events","items":[{"eventType":"variable","name":"REGEX_VARIABLE","type":"string","initialValue":"\\{(\\S+)\\}","comment":"{gold}","isStatic":true,"isConstant":true},{"functionName":"ParseFormat","functionDescription":"","functionCategory":"","functionReturnType":"string","functionIsAsync":false,"functionParameters":[{"name":"source","type":"string","initialValue":"","comment":""}],"eventType":"function-block","conditions":[],"actions":[],"children":[{"eventType":"variable","name":"parseText","type":"string","initialValue":"","comment":"","isStatic":false,"isConstant":false},{"eventType":"block","conditions":[{"id":"test-regex","objectClass":"System","parameters":{"string":"source","regex":"REGEX_VARIABLE","flags":"\"\""}}],"actions":[{"id":"set-eventvar-value","objectClass":"System","parameters":{"variable":"parseText","value":"source"}}],"children":[{"eventType":"block","conditions":[{"id":"for","objectClass":"System","parameters":{"name":"\"\"","start-index":"0","end-index":"RegexMatchCount(source, REGEX_VARIABLE, \"g\") - 1"}}],"actions":[],"children":[{"eventType":"variable","name":"MatchKey","type":"string","initialValue":"","comment":"","isStatic":false,"isConstant":false},{"eventType":"variable","name":"MatchValue","type":"string","initialValue":"","comment":"","isStatic":false,"isConstant":false},{"eventType":"block","conditions":[],"actions":[{"id":"set-eventvar-value","objectClass":"System","parameters":{"variable":"MatchKey","value":"RegexMatchAt(source, REGEX_VARIABLE, \"g\", loopindex)"}},{"id":"set-eventvar-value","objectClass":"System","parameters":{"variable":"MatchValue","value":"Dictionary.Get(mid(MatchKey, 1, len(MatchKey)-2))"}},{"id":"set-eventvar-value","objectClass":"System","parameters":{"variable":"parseText","value":"RegexReplace(ParseText, REGEX_VARIABLE, \"\", MatchValue)"}}]}]},{"eventType":"block","conditions":[],"actions":[{"id":"set-function-return-value","objectClass":"Functions","parameters":{"value":"parseText"}}]}]},{"eventType":"block","conditions":[{"id":"else","objectClass":"System"}],"actions":[{"id":"set-function-return-value","objectClass":"Functions","parameters":{"value":"source"}}]}]}]}
---
It uses regular expressions to match.
Hi, {name}! You Have {gold} G!
Use RegexMatchCount
to find how many variables need to be replaced in this string. it is 2
RegexMatchCount(source, "\{(\S+)\}", "g")
and then use a loop to through it. 0 ~ 1
For "" from 0 to RegexMatchCount(source, REGEX_VARIABLE, "g") - 1
and then Use RegexMatchAt
to replace the variable. it is '{name}' and '{gold}'.
MatchKey = RegexMatchAt(source, REGEX_VARIABLE, "g", loopindex)
and then Use mid(text, index, count)
extract content.
mid(MatchKey , 1, len(MatchKey)-2)
MatchValue = Dictionary.Get(mid(MatchKey, 1, len(MatchKey)-2))
and then Use RegexReplace
to replace the Dictionary value.