Link to home
Start Free TrialLog in
Avatar of Camillia
CamilliaFlag for United States of America

asked on

Parse phone number

I have a string with a phone number. I want to parse the phone number. I tried this and I can't get to the numbers. How can I do this?

  string dastoor =
                "Dear Dr. Lewis: I am referring Margaret xyz (DOB 2/26/yyyy (74 y.o.)) to you for evaluation of PC HAZE OS- AG.The following is a summary of my findings on 7 / 16 / 2014. Patient Home Phone: (222)333-4444 ";

            string dastoorSentenceHomePhone = string.Empty;
            try
            {
               var dastoorTobSearched = "Patient Home Phone:".ToLower();
               var dastoorSentence = dastoor.Substring(dastoor.IndexOf(dastoorTobSearched) + dastoorTobSearched.Length).Trim().ToLower();
               var closingDastoorComma = dastoorSentence.IndexOf(": (");
                dastoorSentenceHomePhone = dastoorSentence.Substring(0, closingDastoorComma).Trim();

                Regex tonumbers = new Regex(@"[^\d]");
                // var  stripped_phonenumber = tonumbers.Replace(dastoorSentenceHomePhone, "");
                //if (stripped_phonenumber != string.Empty)
                //{
                //    string phone2zip = stripped_phonenumber.Substring(0, 3);
                //    string phone2FirstPart = stripped_phonenumber.Substring(3, 3);
                //    string phone2SecondPart = stripped_phonenumber.Substring(6, 4);
                //}
            }
            catch (Exception)
            {

          
            }

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Bill Prew
Bill Prew

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Camillia

ASKER

let me see. Thanks
Yeah , that worked. Now I see what I was missing.
Avatar of Bill Prew
Bill Prew

Great, glad that helped.


»bp