SolvedPrivate

How can I parse this date of the string?

Posted on 2014-07-26
4
33 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

The Orion Papers

Are you interested in becoming an AWS Certified Solutions Architect?

Discover a new interactive way of training for the exam.

Question has a verified solution.

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

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

707 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