?
SolvedPrivate

How can I parse this date of the string?

Posted on 2014-07-26
4
Medium Priority
?
35 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 2000 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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

741 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