C # function, padleft (), fill in the specified number of spaces.

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.