Returns a new string that is filled with spaces on the left of the characters in this instance to reach the specified total length, so as to achieve right alignment.
Namespace:System
ProgramSet:Mscorlib(In mscorlib. dll)Public StringPadleft (
IntTotalwidth
) Parameters
- Totalwidth
-
Type: System .Int32
The number of characters in the result string, equal to the number of original characters plus any other character.
Return Value
Type: System.String
A new string equivalent to this instance, but the string is right aligned. Therefore, fill in the required number of spaces on the left side to make the length reachTotalwidth. IfTotalwidthIf the length is less than the length of the instance, the new string is the same as that of the instance.
Exception
| Exception |
Condition |
| Argumentoutofrangeexception |
TotalwidthLess Than Zero. |
Remarks
Unicode spaces are defined as hexadecimal 0x20.
padleft (int32) method pads the beginning of the returned string. "data-guid =" 4b73f6801fa2f286b9af3f3966aa87b6 "> padleft (int32) fills in the beginning of the returned string. this means that when you use this method for right-to-left language, it fills the right part of the string.
| Note: |
This method does not modify the value of the current instance. Instead, a new string is returned, which fills in leading spaces to make the total length of the stringTotalwidthCharacters. |
Example
The following examplePadleftMethod.
C #
StringSTR ="BBQ and slaw"; Console. writeline (Str. padleft (15 ));// Displays "BBQ and slaw ".Console. writeline (Str. padleft (5 ));// Displays "BBQ and slaw ".
Converted from msdn: http://msdn.microsoft.com/zh-cn/library/0zk6ydzx