Assume there is a string:
"I'm a boy."
and some synonyms words (in key-value format):
boy -> "male yong"
yong -> "age under 18"
If I replace the string by synonyms words one by one, it will be:
Step 1, find word "boy" and replace it: "I'm a male young."
Step 2, find word "young" and replace it: "I'm a male age under 18."
Actually I need not recursive replacement, I need only replace the orginal string, in other words the step 2 should find "young" in orginal string:"I'm a boy." not the "I'm a male young." There is a simple solution:
Firstly replace key to %s and add synonyms word to a list:
string: "I'm a %s"
list: "male yong"
Then format string with list:
String.format(string, list)
It works fine but stupid and slow, anyone have more clear solution?