NAnt SDK Documentation - v0.92

StringFunctions.PadLeft Method 

Returns the given string left-padded to the given length.

[Visual Basic]
<Function(Name:="pad-left")>
Public Shared Function PadLeft( _
   ByVal s As String, _
   ByVal totalWidth As Integer, _
   ByVal paddingChar As String _
) As String
[C#]
[Function(Name="pad-left")]
public static string PadLeft(
   string s,
   int totalWidth,
   string paddingChar
);

Parameters

s
The String that needs to be left-padded.
totalWidth
The number of characters in the resulting string, equal to the number of original characters plus any additional padding characters.
paddingChar
A Unicode padding character.

Return Value

If the length of s is at least totalWidth, then a new String identical to s is returned. Otherwise, s will be padded on the left with as many paddingChar characters as needed to create a length of totalWidth.

Remarks

Note that only the first character of paddingChar will be used when padding the result.

Exceptions

Exception Type Condition
ArgumentException totalWidth is less than zero.

Example

string::pad-left('test', 10, ' ') ==> '      test'
string::pad-left('test', 10, 'test') ==> 'tttttttest'
string::pad-left('test', 3, ' ') ==> 'test'
string::pad-left('test', -4, ' ') ==> ERROR

See Also

StringFunctions Class | NAnt.Core.Functions Namespace