Method to replace substring.