The other Meterpreter implementations do a `replace` across the whole string which has the same effect. It probably isn't necessary, but it was there for consistency.

I did try to use `StringBuilder` first, but that wasn't supported by earlier Java versions, neither were `replace` and `replaceAll`. So I had to resort to substring hacks.