Solved

Format SSN

Posted on 2007-04-09
4
919 Views
Last Modified: 2008-03-10
Not sure how to do this:
In the database, there's a table that holds the SSN format. For example, client1 might want their SSNs to look like 999-99-9999. Client2 might want their SSN to look like 999/99/9999. Client3 might want their SSN to look like 99-999-9999.

*** So the separater and the # of digits to the side of the separators might change.
The SSNs are stored as 999999999 in the database. Before displaying them in the gridview, I need to format them based on what  the client wants them displayed...

SO I read 111228888, format, for example is 99-999-9999...then what? I think i need a class/routine to maybe read the format from the database, maybe parse the 9's before and after the separator, maybe count the digits and then parse the actual SSN like that?? any ideas?
0
Comment
Question by:Camillia
  • 2
  • 2
4 Comments
 
LVL 23

Accepted Solution

by:
Jens Fiederer earned 500 total points
ID: 18875572
This should not be that complicated.  

123456.ToString("0-0-000-0")
produces
"1-2-345-6"

so all you need is the data to format and the format string, and the framework does the rest.
0
 
LVL 7

Author Comment

by:Camillia
ID: 18875600
so, read the format from the database, stick it in ToString?

Like this: 999/99/9999  :   111223333.ToString("999/99/9999") -- > 111/22/3333
?

0
 
LVL 23

Expert Comment

by:Jens Fiederer
ID: 18875632
Yes.  Of course, in your actual code you won't be using constants.  It will probably be more like

YourDataReader("columnName").ToString(formatYouLoadedForUser)
0
 
LVL 7

Author Comment

by:Camillia
ID: 18875651
thanks.
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

867 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

15 Experts available now in Live!

Get 1:1 Help Now