reverse, replace trim* implementation