replace string value with corresponding frequency