Solved

String formatting

Posted on 2004-10-17
4
151 Views
Last Modified: 2010-04-23
I have Integer variable which I want to convert into String.
I want to create the string in a specific pattern of 3 digits.

Example:
My Integer is 1 => string will be "001"
My Integer is 11 => string will be "011"


Thanx, El.
0
Comment
Question by:eladka
4 Comments
 
LVL 20

Accepted Solution

by:
ihenry earned 63 total points
ID: 12331682
Try the following code,

        Dim i As Integer = 1
        Dim j As Integer = 11
        Console.WriteLine(i.ToString("000"))
        Console.WriteLine(j.ToString("000"))
0
 
LVL 1

Assisted Solution

by:ndonhauser
ndonhauser earned 62 total points
ID: 12340325
This is another way to do it...

Dim intNumber1 as integer = 1
Dim intNumber2 as integer = 11

intNumber1.ToString.PadLeft(3, CChar("0"))
intNumber2.ToString.PadLeft(3, CChar("0"))

Explanation...
PadLeft(length that you want the final string to be, Char that you want to add to the left of the number)
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question