我想用 )
替换最后一个 ,
字符串。
假设字符串是:
Insert into dual (name,date,
要转换成:
Insert into dual (name,date)
最佳答案
以下代码应将最后出现的 ','
替换为 ')'
。
StringBuilder b = new StringBuilder(yourString);
b.replace(yourString.lastIndexOf(","), yourString.lastIndexOf(",") + 1, ")" );
yourString = b.toString();
注意如果 String
不包含 ','
,这将引发异常。
关于java - 替换字符串的最后一部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1660034/