Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Advanced String Manipulation (C#)

Reply
Thread Tools

Advanced String Manipulation (C#)

 
 
Aaron
Guest
Posts: n/a
 
      01-02-2004
I would like to randomly output phone numbers seperated by \ and / from a string.
s = "\231-3423/\453-1234/\231-3473/\231-3474/"

//c sharp code
private string GetPhoneNum()
{
s = "\231-3423/\453-1234/\231-3473/\231-3474/"
//randomly pick a phone num from string.

n = randomNum;
return n;//ie. 453-1234
}

Thanks
 
Reply With Quote
 
 
 
 
Arthur Nesterovsky
Guest
Posts: n/a
 
      01-02-2004
Hi Aaron,

> I would like to randomly output phone numbers seperated by \ and / from a

string.
> s = "\231-3423/\453-1234/\231-3473/\231-3474/"
>
> //c sharp code
> private string GetPhoneNum()
> {
> s = "\231-3423/\453-1234/\231-3473/\231-3474/"
> //randomly pick a phone num from string.
>
> n = randomNum;
> return n;//ie. 453-1234
> }


Try to use the regular expressions:

Regex re = new Regex(@"\([0-9]{3}-[0-9]{4})/", RegexOptions.Multiline);
MatchCollection m = re.Matches(s);
return m[n].Group[1].Value; // n = 0..count-1, where count is a total number
of phone numbers.

--
______________________________
With best wishes, Arthur Nesterovsky
Visit, please, my home page:
http://www.nesterovsky-bros.com


 
Reply With Quote
 
 
 
 
Nick
Guest
Posts: n/a
 
      01-02-2004
private string GetPhoneNumber() {
s = "\231-3423/\453-1234/\231-3473/\231-3474/";
string[] num = String.Split(s, "/\");

return num[n];
}


"Aaron" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) om...
> I would like to randomly output phone numbers seperated by \ and / from a

string.
> s = "\231-3423/\453-1234/\231-3473/\231-3474/"
>
> //c sharp code
> private string GetPhoneNum()
> {
>
> //randomly pick a phone num from string.
>
> n = randomNum;
> return n;//ie. 453-1234
> }
>
> Thanks



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Advanced Python Programming Oxford Lectures [was: Re: *Advanced*Python book?] Michele Simionato Python 1 03-27-2010 06:10 AM
Help with Repeater control and advanced data manipulation Mike Cain ASP .Net 2 10-22-2006 09:31 AM
advanced string manipulation MC felon C++ 4 10-08-2006 10:20 AM
Perl string manipulation jared in ecs Perl 2 10-22-2003 05:36 PM
String Array Manipulation Problem Garfield ASP .Net 5 08-27-2003 10:07 PM



Advertisments