Link to home
Start Free TrialLog in
Avatar of EDCTECH
EDCTECH

asked on

Need help with formating a number

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?
Avatar of Kenneth Brown
Kenneth Brown
Flag of United Kingdom of Great Britain and Northern Ireland image

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.
ASKER CERTIFIED SOLUTION
Avatar of Miguel Oz
Miguel Oz
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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)
Avatar of EDCTECH
EDCTECH

ASKER

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))