How to fill a string with a repeated character in C#

by Emanuele 6/24/2008 11:36:00 AM

How to format the string "abc" with "000000000abc" in c#?

It's very simple.
You can use the method PadLeft of the string object.
This method has two parameters.
The first is the number of times that the character will repeat.
The second is the Char value to repeat.

            string str;
            char charzero;
            str = "abc";
            charzero = '0';
            string Result = str.PadLeft(9, charzero);

 

 

Tags:

Asp.Net

Related posts



Powered by BlogEngine.NET 1.3.1.0
Theme by Emanuele Bartolesi

About the author

Name of author Emanuele Bartolesi
I'm a senior developer and project manager.

Contact me Contact me

Calendar

<<  December 2008  >>
MoTuWeThFrSaSu
24252627282930
1234567
891011121314
15161718192021
22232425262728
2930311234

View posts in large calendar

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2008

Sign in

Download Day 2008