Solved

String formatting

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

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 …
If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

776 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