且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何用一个字符串替换特殊字符及其下一个字符串

更新时间:2022-11-16 14:13:15

不确定你想要的但是:

String str = "alter table $owner.$table_name ENABLE constraint $constraint_name;"
str = str.replace("$owner", "hr")
    .replace("$table_name", "hr")
    .replace("$constraint_name", "scma_constraint");

Javadoc可用此处

The Javadoc is available here.

replace()方法返回一个新字符串,该字符串是用newChar替换此字符串中所有出现的oldChar(不支持regexp)

The replace() method returns a new string resulting from replacing all occurrences of oldChar in this string with newChar (without the support of regexp)

replaceAll()方法执行相同,但在regexp的支持下。

The replaceAll() method does the same, but with the support of regexp.

如果需要,可以更准确地编辑你想要的问题。

If needed, edit your question with more precision on what you want.