Henry Olive 5 Posted December 17, 2021 I wish everyone a healthy day Edit1.Text := 'AA BB' MyVar := Trim(Edit1.Text); // MyVar is still AA BB, i was expecting to get AABB Thank You Share this post Link to post
Der schöne Günther 316 Posted December 17, 2021 (edited) You may want to look at the online documentation of Trim(..), emphasis by me: Quote Trims leading and trailing spaces and control characters from a string Source: System.SysUtils.Trim - RAD Studio API Documentation (embarcadero.com) You don't want to remove leading and trailing spaces, you apparently want to remove all spaces. Do this by "replacing" the spaces with an empty string, like myString := myString.Replace(' ', ''); Edited December 17, 2021 by Der schöne Günther Share this post Link to post
PeterBelow 238 Posted December 17, 2021 49 minutes ago, Henry Olive said: I wish everyone a healthy day Edit1.Text := 'AA BB' MyVar := Trim(Edit1.Text); // MyVar is still AA BB, i was expecting to get AABB Thank You Are you looking for something like this? {! <summary> Remove all characters in aSet from the passed string and return the resulting string</summary>} function RemoveCharsInSet(const S: string; const aSet: TSysCharset):string; var I: Integer; begin Result := S; for I := Length(S) downto 1 do if S[I] in aSet then Delete(Result, I, 1); end; {! <summary> Remove all characters considered whitespace from the passed string and return the resulting string</summary>} function RemoveWhitespace(const S: string):string; const Whitespace = [#0..' ']; begin Result := RemoveCharsInSet(S, Whitespace); end; Share this post Link to post