SolvedPrivate

How can I parse this date of the string?

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

776 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