Advanced String Manipulation (C#)

Discussion in 'ASP .Net' started by Aaron, Jan 2, 2004.

  1. Aaron

    Aaron Guest

    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
     
    Aaron, Jan 2, 2004
    #1
    1. Advertising

  2. 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
     
    Arthur Nesterovsky, Jan 2, 2004
    #2
    1. Advertising

  3. Aaron

    Nick Guest

    private string GetPhoneNumber() {
    s = "\231-3423/\453-1234/\231-3473/\231-3474/";
    string[] num = String.Split(s, "/\");

    return num[n];
    }


    "Aaron" <> wrote in message
    news:...
    > 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
     
    Nick, Jan 2, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. jared in ecs

    Perl string manipulation

    jared in ecs, Oct 22, 2003, in forum: Perl
    Replies:
    2
    Views:
    821
    Roy Johnson
    Oct 22, 2003
  2. A.M
    Replies:
    2
    Views:
    539
    gene tani
    Jun 16, 2006
  3. Mike Cain
    Replies:
    2
    Views:
    462
    Eliyahu Goldin
    Oct 22, 2006
  4. MC felon

    advanced string manipulation

    MC felon, Oct 8, 2006, in forum: C++
    Replies:
    4
    Views:
    262
    peter koch
    Oct 8, 2006
  5. Michele Simionato
    Replies:
    1
    Views:
    620
    Lacrima
    Mar 27, 2010
Loading...

Share This Page