Solved

String formatting

Posted on 2004-10-17
4
152 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
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 …
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

752 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