Closed. This question does not meet Stack Overflow guidelines。它当前不接受答案。












想改善这个问题吗?更新问题,以使为on-topic

6年前关闭。



Improve this question





如果存在,如何从最后一个索引的字符串中删除特定字符',',是否可以删除?

String str="update employee set name='david', where id=?";

最佳答案

只需尝试以下操作:

int index = str.length() - 2;  //Calculating the index of the 2nd last element
str = str.subString(0,index);  //This shall give you the string without the last element


或者,如果您想删除特定字符,例如“,”:

str.replace(",","");


您还可以使用indexOf()方法(或lastIndexOf()方法)来查找索引并创建两个子字符串,然后合并这些子字符串。
或者,您可以根据字符拆分字符串,然后合并拆分的字符串。

关于java - 从最后一个索引中删除字符串中的特定字符,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/18376018/

10-15 10:42
查看更多