An important thing to know is that if the modified string contains the exact same content as the original string, then the original string is returned and no new string object is created.
It helps to go see what happens under the hood. Here is the code for the substring method:
As you can see, substring returns
this if beginIndex is 0 and endIndex is the index of the last character of the string.
As for the replace method:
you can easily see that if the old and the new char are the same,
this is returned.
I agree it would help it the
doc would mention this information.
[ March 21, 2003: Message edited by: Valentin Crettaz ]