Abstract string replacement to function for clarity