Regular expression help

  • Thread starter Thread starter Mark Taylor
  • Start date Start date
M

Mark Taylor

Hello all -

I have a problem here that I think can be solved using regular
expressions, but not knowing enough about them, I wanted to ask.

I'm pulling data from a database that we're provided that has all data
unformated, all names, addresses, whatever are all in capital letters,
zip codes, phone numbers, social security numbers are all run
together.

For example, we're getting zip code in the form '999999999', and last
name 'TAYLOR'.

What I'd like to do it use a regular expression to change the output
to '99999-9999' for zip codes, '999-99-9999' for social security
numbers and 'Taylor' for 'TAYLOR' and so on...

I've searched through google trying to find a solution. Can this even
be done? If so, could someone point me in the direction of a site
for a solution or provide a short code sample?

Thanks!!

Mark
 
Hi Mark,

Composite string formatting is enough for this:
String.Format("{0:#####-####}", 999999999) gives you 99999-9999
String.Format("{0:###-##-####}", 999999999) gives you 999-99-9999

For first-char casing you can use this:
CultureInfo.CurrentCulture.TextInfo.ToTitleCase("TAYLOR".ToLowerInvariant())
gives you Taylor

Kind Regards, Alex Meleta
[TechBlog] http://devkids.blogspot.com



MT> Hello all -
MT>
MT> I have a problem here that I think can be solved using regular
MT> expressions, but not knowing enough about them, I wanted to ask.
MT>
MT> I'm pulling data from a database that we're provided that has all
MT> data unformated, all names, addresses, whatever are all in capital
MT> letters, zip codes, phone numbers, social security numbers are all
MT> run together.
MT>
MT> For example, we're getting zip code in the form '999999999', and
MT> last name 'TAYLOR'.
MT>
MT> What I'd like to do it use a regular expression to change the output
MT> to '99999-9999' for zip codes, '999-99-9999' for social security
MT> numbers and 'Taylor' for 'TAYLOR' and so on...
MT>
MT> I've searched through google trying to find a solution. Can this
MT> even be done? If so, could someone point me in the direction of a
MT> site for a solution or provide a short code sample?
MT>
MT> Thanks!!
MT>
MT> Mark
MT>
 
Hey Alex -

That's exactly what I needed! Looks like I was trying to make it more
difficult than it had to be.

Thanks so much for the help!

Mark
 
Hi Gugale,

To capitalize first letter of sentence in this particular case (TAYLOR to
Taylor), yes, you should have at least one char lower, because .ToTitleCase
transforms "mr HoRVard wAnt tO USE it" onto "Mr Horvard Want To USE It".

Kind Regards, Alex Meleta
[TechBlog] http://devkids.blogspot.com



GL> Hi Mark,
GL>
GL> Is calling ToLowerInvariant() necessary?
GL>
GL> Thanks
GL> SG
GL> GL>
Hi Mark,

Composite string formatting is enough for this:
String.Format("{0:#####-####}", 999999999) gives you 99999-9999
String.Format("{0:###-##-####}", 999999999) gives you 999-99-9999

For first-char casing you can use this:
CultureInfo.CurrentCulture.TextInfo.ToTitleCase("TAYLOR".ToLowerInvar
iant()) gives you Taylor

Kind Regards, Alex Meleta
[TechBlog] http://devkids.blogspot.com
MT> Hello all -
MT> MT> I have a problem here that I think can be solved using
regular
MT> expressions, but not knowing enough about them, I wanted to ask.
MT> MT> I'm pulling data from a database that we're provided that has
all
MT> data unformated, all names, addresses, whatever are all in
capital
MT> letters, zip codes, phone numbers, social security numbers are
all
MT> run together.
MT> MT> For example, we're getting zip code in the form '999999999',
and
MT> last name 'TAYLOR'.
MT> MT> What I'd like to do it use a regular expression to change the
output
MT> to '99999-9999' for zip codes, '999-99-9999' for social security
MT> numbers and 'Taylor' for 'TAYLOR' and so on...
MT> MT> I've searched through google trying to find a solution. Can
this
MT> even be done? If so, could someone point me in the direction of
a
MT> site for a solution or provide a short code sample?
MT> MT> Thanks!!
MT> MT> Mark
MT
 
Back
Top