SolvedPrivate

How can I parse this date of the string?

Posted on 2014-07-26
4
28 Views
Last Modified: 2016-02-18
I have a string like this and I got the first part done but now need to get the second part

My string is this:
string patientInfo ="Robert Doe (DOB 1/23/1927"  (no right parenthesis)

I got the first and the last name . How do I get month, day and year in separate fields? so, get 1, 23 and 1927

This gets the first, middle and last name
int openParen = patientInfo.IndexOf('(');
                string patientName = patientInfo.Substring(0, openParen).Trim();

                string firtsName;
                string lastName; 
                string middleName;

                //if there's a middle name

                
               string[]  arrNames = patientName.Split(' ');
                if (arrNames.Length > 0)
                {
                    firtsName = arrNames[0];
                }
                if (arrNames.Length > 1)
                {
                    lastName = arrNames[arrNames.Length - 1];
                }
                if (arrNames.Length > 2)
                {
                    middleName = string.Join(" ", arrNames, 1, arrNames.Length - 2);
                }

Open in new window

0
Comment
Question by:Camillia
  • 2
  • 2
4 Comments
 
LVL 58

Expert Comment

by:Gary
ID: 40221839
Using LINQ and  .Last()

dob = arrNames.Last();

else

dob = arrNames[arrNames.Length-1];
0
 
LVL 7

Author Comment

by:Camillia
ID: 40221846
No, both those lines of code give me the last name...not the date of birth.
0
 
LVL 58

Accepted Solution

by:
Gary earned 500 total points
ID: 40221853
Didn't notice you had already split the string

dob = patientInfo.Split('(').Last();

dob_parts=dob.Split('/');
0
 
LVL 7

Author Comment

by:Camillia
ID: 40221863
Yes!, just got it. Thanks.
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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
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 demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

914 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

18 Experts available now in Live!

Get 1:1 Help Now