Solved

String formatting

Posted on 2004-10-17
4
148 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
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…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

757 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now