Solved

String formatting

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

920 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

14 Experts available now in Live!

Get 1:1 Help Now