Home  |  Delphi .net Home  |  System.String  |  PadRight Method
  
PadRight  
Method  
Left aligns a string, padding to the right as appropriate
String Class
System NameSpace
CF1.  Function PadRight ( Length : Integer ) : String;
CF2.  Function PadRight ( Length : Integer; PadChar : Char ) : String;
CF : Methods with this mark are Compact Framework Compatible
Description
This is a badly named method!
 
It should be named LeftAlign since this is what it does. When left aligning a string into a fixed length field, pad characters are necessarily going to be needed!
 
A blank pad character is used unless PadChar is specified.
 
The string is padded on the right with the pad character to make the whole string length match the required Length.
 
If the string is already <= Length then it is returned unchanged.
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;

begin
  strA := '12345';

  strB := strA.PadRight(7);

  Console.WriteLine('Default padding  to 7 characters = ''' + strB + '''');

  strB := strA.PadRight(7, '-');

  Console.WriteLine('Padding with ''-'' to 7 characters = ''' + strB + '''');

  Console.ReadLine;
end.
   Default padding  to 7 characters = '12345  '
   Padding with '-' to 7 characters = '12345--'
 
 
Delphi Programming Neil Moffatt 2002 - 2017. All rights reserved.  |  Contact the author