Home  |  Delphi .net Home  |  System.String  |  Trim Method
  
Trim  
Method  
Trims specified characters from both ends of a string
String Class
System NameSpace
CF1.  Function Trim : String;
CF2.  Function Trim ( CharArray : Array of Char ) : String;
CF : Methods with this mark are Compact Framework Compatible
Description
By default, it will remove any leading or trailing blanks from the current string.
 
If you supply a CharArray then it will remove all such characters from the start and end of the string. The characters can be in any order - removal proceeds at each end until a string character is found that is not in the character array.
Notes
Like a lot of string methods, the string object itself is not affected - the modified string is returned for assignment.
Microsoft MSDN Links
System
System.String
 Author links

 Buy Website Traffic at
 Buywebsitetrafficexperts.com

 Buy Proxies at
 Buyproxies.io
 
 
 
A simple example
program Project1;
{$APPTYPE CONSOLE}

var
  strA, strB : String;
  charArray  : Array[0..1] of Char;

begin
  strA := '  --- Hello  --   ';
  charArray[0] := ' ';
  charArray[1] := '-';

  Console.WriteLine('strA = ''' + strA + '''');

  strB := strA.Trim;

  Console.WriteLine('Trimming using default character');
  Console.WriteLine('strB = ''' + strB + '''');

  strB := strA.Trim(charArray);

  Console.WriteLine('Trimming both ends of '' '' and ''-'' chars');
  Console.WriteLine('strB = ''' + strB + '''');

  Console.ReadLine;
end.
   strA = '  --- Hello  --   '
   Trimming using default character
   strB = '--- Hello  --'
   Trimming both ends of ' ' and '-' chars
   strB = 'Hello'
 
 
Delphi Programming Neil Moffatt 2002 - 2017. All rights reserved.  |  Contact the author