Solved

Need help with formating a number

Posted on 2011-09-14
4
260 Views
Last Modified: 2013-11-07
I need to format an 11 digit number like this 999-999-99-999 and display it in a label.  The formatting is just for display purposes. The number is stored without the dashes in the database. I've tried using String.Format but haven't had much luck. Any ideas?
0
Comment
Question by:EDCTECH
4 Comments
 
LVL 5

Expert Comment

by:Kenneth Brown
ID: 36539912
Write some code to split your 11 digit string into 4 sep strings
abc-def-gh-ijk -> s1,s2,s3,s4
use the string.mid function (in vb)
http://msdn.microsoft.com/en-us/library/aa903372(VS.71).aspx

then use string.format on those, adding dashes as necc.
0
 
LVL 35

Accepted Solution

by:
Miguel Oz earned 500 total points
ID: 36539924
0
 
LVL 40
ID: 36539962
You probably had problem with String.Format becauce you do not know of the backlash trick. When you want to force a specific character in the format, but a backslash in front of it:

String.format("{0:###\-###\-##\-###}",99999999999)
0
 

Author Closing Comment

by:EDCTECH
ID: 36540002
Thanks!  That is what I needed.

  Dim strSelectedParcel As String = String.Format("{0}-{1}-{2}-{3}", _
               btnTemp.Text.Substring(0, 3), _
                btnTemp.Text.Substring(3, 3), _
                btnTemp.Text.Substring(6, 2), _
                btnTemp.Text.Substring(8, 3))
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

813 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

12 Experts available now in Live!

Get 1:1 Help Now