SolvedPrivate

How can I parse this date of the string?

Posted on 2014-07-26
4
27 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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
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.

757 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

21 Experts available now in Live!

Get 1:1 Help Now