I think there is a typo. The length of the replace statement is supposed to be the length of the source. While I agree in many cases this is the same number as the new length, the example is misleading as it implies the length is the length of the new string. That is counter to the documentation.
Thanks -- Tom