Do string replacement properly.