Solved

Help with formatting a couple of numbers in C#

Posted on 2013-06-24
5
163 Views
Last Modified: 2013-06-24
Hey guys!!

I have a date string
                    InitVar.strDOB = AllRx.Rows[odernum]["DOB"].ToString();
 I need to format as follows:
                    19460803

And also a phone number
                    InitVar.strCustPhone = AllRx.Rows[odernum]["PHONE"].ToString();
I need to format as follows:
                    4795555555

Thanks a bunch,
Jerry
0
Comment
Question by:JDL129
  • 2
  • 2
5 Comments
 
LVL 40

Accepted Solution

by:
Kyle Abrahams earned 100 total points
ID: 39272621
For the first:
DateTime.Parse(InitVar.strDOB).ToString("yyyymmdd");
For the second:


for the second:
  string s = "(515) 555 - 2323";
                string t = "";
                foreach( char c in s.ToCharArray())
                    if (char.IsDigit(c))
                        t += c;
0
 
LVL 62

Assisted Solution

by:Fernando Soto
Fernando Soto earned 100 total points
ID: 39272645
Hi JDL129;

The following should do what you need. In the PHONE if there are other formatting characters other then ( ) - add them to the part of the Regex pattern in "[/() -]", after the "[ and before -, the - should be the last one.


using System.Text.RegularExpressions;

InitVar.strDOB = DateTime.Parse(AllRx.Rows[odernum]["DOB"].ToString()).ToString("yyyyMMdd");

InitVar.strCustPhone = Regex.Replace(AllRx.Rows[odernum]["PHONE"].ToString(),
                             "[/() -]", "");

Open in new window

0
 
LVL 40

Expert Comment

by:Kyle Abrahams
ID: 39272700
Just noticed that the format string in mine had small m's.  Those are for minutes . . . capital M's is correct for months.

eg:
 ToString("yyyyMMdd");
0
 

Author Comment

by:JDL129
ID: 39272823
Upped the points
0
 

Author Closing Comment

by:JDL129
ID: 39272827
Thanks guys!!!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

861 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

25 Experts available now in Live!

Get 1:1 Help Now