String replace and while loop