• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 173
  • Last Modified:

String Parse Question

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

781-233-3233
1234

without the x this time for the strings I need.  Thanks so much
0
sbornstein2
Asked:
sbornstein2
  • 2
  • 2
1 Solution
 
Joel CoehoornDirector of Information TechnologyCommented:
Look at string.Split():

string phone = "781-232-3233 x1234";
string[] phoneparts = phone.Split(new char[] { 'x' }, 2);

Open in new window

0
 
sbornstein2Author Commented:
how do I get the first part.
0
 
Joel CoehoornDirector of Information TechnologyCommented:
phoneparts[0]
0
 
anarki_jimbelCommented:
I'd also call Trim() on each part as these parts may have trailing  (or might be starting) spaces:

phoneparts[0].Trim()
0
 
sbornstein2Author Commented:
awesome thanks a lot
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now