public StringBuffer deleteCharAt(int index),删除缓冲指定位置的字符 public StringBuffer replace(int start,int end,String str),把缓冲区指定位置的字符串替换为新的字符串 public StringBuffer reverse(),字符串反转(倒) public String toString(),把StringBuffer转换为String类型 1. 2. 3. 4. 5. 6. 7. ...
总结:增:append(xxx)删:delete(intstart,int end)改:setCharAt(intn ,char ch) / replace(int start, int end, String str)查:charAt(intn )插:insert(intoffset, xxx)长度:length();*遍历:for()+ charAt() / toString() @Testpublicvoidtest1(){StringBufferbuffer=newStringBuffer("abc");/*增*/b...
StringBuffer replace(start,end,string); //截取start-end,包括start,不包括end,更新为string void setCharAt(int index,char ch); 只可以替换某一个字符 public static void update(){ StringBuffer sb1 = new StringBuffer("javascript"); //截取4-10,包括4,不包括10,更新为ee StringBuffer sb2 = sb1.r...
StringBufferreplace(int start, int end, String str) Replaces the characters in a substring of this sequence with characters in the specified String ·字符串的反转 StringBufferreverse() Causes this character sequence to be replaced by the reverse of the sequence. ·某个字符串的倒序索引 intlastIn...
sb.replace(0,6,"NBProPlusMax Xs");//将索引[0,6)位置上字符换为NBMaxSystem.out.println(sb);//NBProPlusMax Xs Fengsb.setCharAt(6,'!');//将索引6处替换为 !System.out.println(sb);//NBProP!usMax Xs Feng//查sb =newStringBuffer("YuZhen Feng");for(inti=0; i < sb.length(); i...
1.4替换指定位置的内容replace public class StringBufferDemo05{ public static void main(String args[]){ StringBuffer buf = new StringBuffer() ; // 声明StringBuffer对象 buf.append("Hello ").append("World!!") ; // 向StringBuffer添加内容 ...
public StringBuffer replace(int start, int end, String str) Replaces the characters in a substring of this sequence with characters in the specified String. The substring begins at the specified start and extends to the character at index end - 1 or to the end of the sequence if no such...
Added in 1. C# 複製 [Android.Runtime.Register("replace", "(IILjava/lang/String;)Ljava/lang/StringBuffer;", "")] public Java.Lang.StringBuffer Replace (int start, int end, string str); Parameters start Int32 the inclusive begin index. end Int32 the exclusive end index. str String...
从上面的三个方法可以看出,无论是subString、concat还是replace操作都不是在原有的字符串上进行的,而是重新生成了一个新的字符串对象。也就是说进行这些操作后,最原始的字符串并没有被改变。 所以,我们需要记住:对String对象的任何改变都不影响到原对象,相关的任何change操作都会生成新的对象。
public StringBuffer replace(int start, int end, String str)Replaces the characters in a substring of this sequence with characters in the specified String. The substring begins at the specified start and extends to the character at index end - 1 or to the end of the sequence if no such ...