Replace multiple characters in a string in Java

后端 未结 4 437
暗喜
暗喜 2020-12-22 07:26

I have some strings with equations in the following format ((a+b)/(c+(d*e))).

I also have a text file that contains the names of each variable, e.g.:

4条回答
  •  难免孤独
    2020-12-22 08:13

    I'd make a hashMap mapping the variable names to the descriptions, then iterate through all the characters in the string and replace each occurrance of a recognised key with it's mapping. I would use a StringBuilder to build up the new string.

提交回复
热议问题