How do I fix 0 before the C # string is less than the number of digits?

Source: Internet
Author: User

You can easily complement a string using PadLeft and PadRight in C #.

PadLeft (int totalwidth, char Paddingchar)//To the left of the string to complement totalwidth length with Paddingchar

PadLeft (int totalwidth, char Paddingchar)//to the right of the string to complement totalwidth length with Paddingchar

For example:

1, string aa = "WU";

string bb = aa. PadLeft (6)//Right aligns the characters in this instance, padding on the left with spaces to reach the specified total length.

string cc = AA. PadLeft (6, ' 0 ');/Right aligns the characters in this instance, padding on the left with the specified Unicode character to reach the specified total length.

2, pznm = (snode. innertext). ToString (). PadLeft (10, ' 0 ');

The string is fixed to 10 bits, and less than 10 bits to the left complement 0.

This paper url:http://www.bianceng.cn/programming/csharp/201410/45590.htm

Related Article

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.