How to replace special character and its next string with one string

前端 未结 4 1687
无人共我
无人共我 2021-01-22 16:30

How to replace the special character $owner with \"hr\" and $table_name with \"hr\" and $constraint_name with \"scma_constraint\" in dynamic. Change

\"alter ta         


        
4条回答
  •  面向向阳花
    2021-01-22 16:49

    If you want to replace all matches, then use replaceAll() method and you need to escape special characters like dollar because replaceAll() gets a regex as first parameter and if you write "$owner" it will mean that your string must start with "owner".

    myString.replaceAll("\\$owner", "hr")
    .replaceAll("\\$table_name", "hr")
    .replaceAll("\\$constraint_name", "scma_constraint" );
    

提交回复
热议问题