13 Votes

Delphi: Trim, TrimLeft and TrimRight - Cut off whitespace from a string

Info by Delphian | 2012-10-04 at 14:49

Cutting off white space such as blanks, tabs and line breaks from the front and the rear of a string is an easy task in Delphi and Lazarus. Delphi and Lazarus are providing the functions Trim, TrimLeft and TrimRight for this. Let's have a look at an example:

var
   str, str1, str2, str3: string;
begin
   str := '   ABC   ';

   str1 := Trim(str);       // "ABC"
   str2 := TrimLeft(str);   // "ABC   "
   str3 := TrimRight(str);  // "   ABC"
end;

We are processing the string "   ABC   " by using Trim, TrimLeft and TrimRight. Trim is cutting the spaces at the front and the rear of the string. TrimLeft and TrimRight are cutting the white space only at the left or the right side.

ReplyPositiveNegative

About the Author

AvatarThe author has not added a profile short description yet.
Show Profile

 

Related Topics

Important Note

Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.

Participate

Ask your own question or write your own article on askingbox.com. That’s how it’s done.