More Group Sites
Education Books
School Rankings
Jobless Net
Better Home
Enviro++
更好教育论坛


Help | Subscribe/Unsubscribe | Rules | Other Group Sites: Better Education | Better Education Forum
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Share
Options
View
Go to last post Go to first unread
hong  
#1 Posted : Thursday, 7 October 2010 4:11:29 PM(UTC)
hong

Rank: Administration

Reputation:

Groups: AcademicCoachingSchool, admin, Administration, BookSeller, CatholicSchool, CoachingAdult, CoachingProfessional, CoachingSports, ExtraCurriculumCoaching, IndependentSchool, Moderator, MusicTeacher, PrivateSchool, PublicSchool, SelectiveSchool, tutor
Joined: 23/11/2008(UTC)
Posts: 519

Choose one of the following ways for padding a number with zeros:
Note that a number can be converted to string via ToString().

1. using the Format method of string
Code:
string strTemp = String.Format("{0:0000}", aStr);


2. using PadLeft() or PadRigh() method of string
Code:
aStr.PadLeft(nTotalWidth, '0');


Related:
Padding with spaces
Code:
aStr.PadLeft(nTotalWidth);


Padding right
Code:
aStr.PadRight(nTotalWidth);


3. classic way
Code:
                strTemp = "0000" + aStr;
                strTemp = strTemp.Substring(strTemp.Length - 4);


4. More on string formatting
http://blog.stevex.net/s...ng-formatting-in-csharp/
Sponsor
Michael Caine  
#2 Posted : Tuesday, 19 July 2011 4:01:35 PM(UTC)
Michael Caine

Rank: Newbie

Reputation:

Groups: Member
Joined: 19/07/2011(UTC)
Posts: 1

Very nice and useful posts. Thank a lot.
helsywarner  
#3 Posted : Tuesday, 23 April 2013 4:49:24 PM(UTC)
helsywarner

Rank: Newbie

Reputation:

Groups: Member
Joined: 23/04/2013(UTC)
Posts: 1

follow the link , it gives more samples of string formatting

http://csharp.net-inform...csharp-string-format.htm

helsy
Rss Feed  Atom Feed
Users browsing this topic
Guest (2), Bingbot
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.