MCPcopy Create free account
hub / github.com/codenameone/CodenameOne / replace

Method replace

vm/JavaAPI/src/java/lang/String.java:663–687  ·  view source on GitHub ↗

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 tha

(char oldChar, char newChar)

Source from the content-addressed store, hash-verified

661 * "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)
662 */
663 public java.lang.String replace(char oldChar, char newChar){
664 char[] buffer = value;
665 int _offset = offset;
666 int _count = count;
667
668 int idx = _offset;
669 int last = _offset + _count;
670 boolean copied = false;
671 while (idx < last) {
672 if (buffer[idx] == oldChar) {
673 if (!copied) {
674 char[] newBuffer = new char[_count];
675 System.arraycopy(buffer, _offset, newBuffer, 0, _count);
676 buffer = newBuffer;
677 idx -= _offset;
678 last -= _offset;
679 copied = true;
680 }
681 buffer[idx] = newChar;
682 }
683 idx++;
684 }
685
686 return copied ? new String(buffer) : this;
687 }
688
689 /**
690 * Replaces each substring of this string that matches the literal target sequence with the specified literal replacement sequence.

Callers 15

downloadImageMethod · 0.95
extractTarHeaderMethod · 0.95
endElementMethod · 0.95
exectuteMethod · 0.95
actionPerformedMethod · 0.95
getValueMethod · 0.95
resolveTypeMethod · 0.95
getTypeDescriptorMethod · 0.95
mainMethod · 0.95
mainMethod · 0.95

Calls 6

arraycopyMethod · 0.95
appendMethod · 0.95
toStringMethod · 0.95
indexOfMethod · 0.95
toStringMethod · 0.65
lengthMethod · 0.65