String Parse Question

Posted on 2008-06-23
Last Modified: 2013-11-05
hello all.  I have two fields a work phone and work extension textbox.  I am going to concat these together and place a "x" then the extension if the textbox is not null.  I then need to figure out how to string parse it to get the work phone and extension seperate any idea?

781-232-3233 x1234


without the x this time for the strings I need.  Thanks so much
Question by:sbornstein2
  • 2
  • 2
LVL 18

Accepted Solution

jcoehoorn earned 250 total points
ID: 21847771
Look at string.Split():

string phone = "781-232-3233 x1234";

string[] phoneparts = phone.Split(new char[] { 'x' }, 2);

Open in new window


Author Comment

ID: 21848580
how do I get the first part.
LVL 18

Expert Comment

ID: 21848891
LVL 29

Expert Comment

ID: 21850728
I'd also call Trim() on each part as these parts may have trailing  (or might be starting) spaces:


Author Closing Comment

ID: 31469823
awesome thanks a lot

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
C# application error "Parameter Is Not Valid". 3 79
DateTimepicker 4 33
Error in JQuery 5 37
Facial recognition to look through the whole database for a person 3 40
In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

911 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

16 Experts available now in Live!

Get 1:1 Help Now