Solved

String Parse Question

Posted on 2008-06-23
5
163 Views
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

781-233-3233
1234

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

Accepted Solution

by:
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

0
 

Author Comment

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

Expert Comment

by:jcoehoorn
ID: 21848891
phoneparts[0]
0
 
LVL 29

Expert Comment

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

phoneparts[0].Trim()
0
 

Author Closing Comment

by:sbornstein2
ID: 31469823
awesome thanks a lot
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

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…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

772 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