public java.lang.String replace(char oldChar,char newChar){
  char[] buffer=value;
  int _offset=offset;
  int _count=count;
  int idx=_offset;
  int last=_offset + _count;
  boolean copied=false;
  while (idx < last) {
    if (buffer[idx] == oldChar) {
      if (!copied) {
        char[] newBuffer=new char[_count];
        System.arraycopy(buffer,_offset,newBuffer,0,_count);
        buffer=newBuffer;
        idx-=_offset;
        last-=_offset;
        copied=true;
      }
      buffer[idx]=newChar;
    }
    idx++;
  }
  return copied ? new String(buffer) : this;
}

public java . lang . String replace ( char oldChar , char newChar ) { char [ ] buffer = value ; int _offset = offset ; int _count = count ; int idx = _offset ; int last = _offset + _count ; boolean copied = false ; while ( idx < last ) { if ( buffer [ idx ] == oldChar ) { if ( ! copied ) { char [ ] newBuffer = new char [ _count ] ; System . arraycopy ( buffer , _offset , newBuffer , 0 , _count ) ; buffer = newBuffer ; idx -= _offset ; last -= _offset ; copied = true ; } buffer [ idx ] = newChar ; } idx ++ ; } return copied ? new String ( buffer ) : this ; }
returns a new string resulting from replacing all occurrences of oldchar in this string with newchar . if the character oldchar does not occur in the character sequence represented by this string object , then a reference to this string object is returned . otherwise , a new string object is created that represents a character sequence identical to the character sequence represented by this string object , except that every occurrence of oldchar is replaced by an occurrence of newchar . examples : " mesquite in your cellar " . replace ( ' e ' , ' o ' ) returns " mosquito in your collar " " the war of baronets " . replace ( ' r ' , ' y ' ) returns " the way of bayonets " " sparring with a purple porpoise " . replace ( ' p ' , ' t ' ) returns " starring with a turtle tortoise " " jonl " . replace ( ' q ' , ' x ' ) returns " jonl " ( no change )
