get numbers from string

Discussion in 'ASP .Net' started by Alexander Widera, Jun 13, 2005.

  1. hi,

    i have a string "testing123testing".... I want out of this string only the
    numbers (123) ... how can i make this?
    perhaps there are some more difficulties ... if the string is
    "testing123test456anothertest" ... i want both numbers ... 123 and 456 ...

    thanks

    Alex
     
    Alexander Widera, Jun 13, 2005
    #1
    1. Advertising

  2. Alexander Widera

    Guest

    Thats a job for regular expressions. Dont be scared of them. If you are intrested
    i recommend the book http://www.oreilly.com/catalog/regex/ by Friedl

    The following code will help you on the way

    Dim re As New Regex("\d+")

    Dim matches As MatchCollection = re.Matches("test887rere95zzz")
    Dim match As Match

    For Each match In matches
    Response.Write("-" & match.Groups(0).ToString)
    Next



    Cheers,
    Tom Pester

    > hi,
    >
    > i have a string "testing123testing".... I want out of this string only
    > the
    > numbers (123) ... how can i make this?
    > perhaps there are some more difficulties ... if the string is
    > "testing123test456anothertest" ... i want both numbers ... 123 and 456
    > ...
    > thanks
    >
    > Alex
    >
     
    , Jun 13, 2005
    #2
    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. Subra
    Replies:
    25
    Views:
    1,256
    user923005
    Mar 8, 2007
  2. Andrew Tatum

    Fibonacci Numbers and Lucas Numbers

    Andrew Tatum, May 26, 2007, in forum: C++
    Replies:
    6
    Views:
    607
    Howard
    May 27, 2007
  3. Lance Hoffmeyer
    Replies:
    2
    Views:
    549
    Lance Hoffmeyer
    Jul 26, 2007
  4. jko170
    Replies:
    9
    Views:
    137
    jko170
    Jan 21, 2009
  5. GIMME
    Replies:
    5
    Views:
    200
    Thomas 'PointedEars' Lahn
    Jul 26, 2004
Loading...

Share This Page