if (str[i]=' ') and (str[i+1]=' ') then delete(str,i,1);
if (str[i]=' ') then while (str[i+1]=' ') do delete(str,i,1);