Solved

Format SSN

Posted on 2007-04-09
4
920 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

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

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

16 Experts available now in Live!

Get 1:1 Help Now