The "spaces" are actually char code 160's; therefore,
=SUBSTITUTE(D2,CHAR(160),"")