Replace multiple characters in a string in Java

后端 未结 4 428
暗喜
暗喜 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 07:50

    For string str, use the replaceAll() function:

    str = str.toUpperCase();  //Prevent substitutions of characters in the middle of a word
    str = str.replaceAll("A", "velocity");
    str = str.replaceAll("B", "distance");
    //etc.
    

提交回复
热议问题