本文介绍了如何用一个字符串替换特殊字符及其下一个字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在动态中将hr和$ table_name替换为hr,将$ constraint_name替换为scma_constraint。
更改
How to replace the special character $owner with "hr" and $table_name with "hr" and $constraint_name with "scma_constraint" in dynamic.Change
"alter table $owner.$table_name ENABLE constraint $constraint_name;"
到
"alter table hr.hr ENABLE constraint scma_constraint;"
推荐答案
不确定你想要的但是:
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.
这篇关于如何用一个字符串替换特殊字符及其下一个字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!