Aquí el código y sientanse libres de mejorarlo u optimizarlo
delphi
function DelSpaces(Const Search: String): String; Const BlackSpace = [#33..#126]; Var Index: Byte; Begin Index := 1; While (Index <= Length(Search)) and Not (Search[Index] in BlackSpace) Do Index := Index + 1; result := copy(Search,Index,255); Index := Length(Result); While (Index >0) and not (Result[Index] in BlackSpace) Do Index := Index -1; result := copy(Result,1,Index); End;