Home  |  Delphi .net Home  |  system.String  |  TrimEnd Method
TrimEnd  
Method  
Trims specified characters from the end of a string
String Class
system NameSpace
CF1.  Function TrimEnd ( CharArray : Array of Char; ) : String;
CF : Methods with this mark are Compact Framework Compatible
Description
Removes selected trailing characters from the current string.
 
It starts at the end and keeps removing characters when they match one of the CharArray characters. It continues back through the string removing characters until it encounters a character not in the 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
 
 
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.TrimEnd(charArray);

  Console.WriteLine('Trimming '' '' and ''-'' chars from the end only');
  Console.WriteLine('strB = ''' + strB + '''');

  Console.ReadLine;
end.
Show full unit code
  strA = '  --- Hello  --   '
  Trimming ' ' and '-' chars from the end only
  strB = '  --- Hello'
 
 
Delphi Programming © Neil Moffatt All rights reserved.  |  Contact the author