StringBuffer sb = new StringBuffer(tmp); int index = sb.lastIndexOf("d"); sb.replace(index,index, "H"); 没测试过,自己可以测试一下。
public class Test { public static void main (String args[]) { String temp="daeeedeeedee";
int replaceCh='d'; char newCh='H'; int lastReplaceCh = temp.lastIndexOf(replaceCh); temp=temp.substring(0,lastReplaceCh-1)+newCh+temp.substring(lastReplaceCh+1,temp.length()); System.out.println(temp);
} }
xGss2000() 的代码改一下就行了: public class Test { public static void main (String args[]) { String temp="daeeedeeedee";int replaceCh='d'; char newCh='H'; int lastReplaceCh = temp.lastIndexOf(replaceCh); temp=temp.substring(0,lastReplaceCh)+newCh+temp.substring //不用-1(lastReplaceCh+1,temp.length()); System.out.println(temp);} }谢谢了
int index = sb.lastIndexOf("d");
sb.replace(index,index, "H");
没测试过,自己可以测试一下。
public static void main (String args[]) {
String temp="daeeedeeedee";
int replaceCh='d';
char newCh='H';
int lastReplaceCh = temp.lastIndexOf(replaceCh);
temp=temp.substring(0,lastReplaceCh-1)+newCh+temp.substring(lastReplaceCh+1,temp.length());
System.out.println(temp);
}
}
的代码改一下就行了:
public class Test {
public static void main (String args[]) {
String temp="daeeedeeedee";int replaceCh='d';
char newCh='H';
int lastReplaceCh = temp.lastIndexOf(replaceCh);
temp=temp.substring(0,lastReplaceCh)+newCh+temp.substring //不用-1(lastReplaceCh+1,temp.length());
System.out.println(temp);}
}谢谢了