Home  |  Delphi .net Home  |  System.String  |  PadLeft Method
  
PadLeft  
Method  
Right aligns a string, padding to the left as appropriate
String Class
System NameSpace
CF1.  Function PadLeft ( Length : Integer ) : String;
CF2.  Function PadLeft ( 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 RightAlign since this is what it does. When right 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 left 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.PadLeft(7);

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

  strB := strA.PadLeft(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