count occurances of digits in a string

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Smokey Grindle

    #1

    count occurances of digits in a string

    any fast way to do this? I just need to check if if a string which could
    have a lot of characters in it if it has numbers and count the number of
    numbers in the string. thanks!


  • =?ISO-8859-1?Q?G=F6ran_Andersson?=

    #2
    Re: count occurances of digits in a string

    Smokey Grindle wrote:
    any fast way to do this? I just need to check if if a string which could
    have a lot of characters in it if it has numbers and count the number of
    numbers in the string. thanks!
    >
    Use the Matches method in the Regex class with a regular expression
    pattern as "\d+" to find all occurances of digits.

    Depending on if you want to count numbers or count digits (which isn't
    really clear), get the number of matches or add the lengths of the matches.

    --
    Göran Andersson
    _____
    Göran Anderssons privata hemsida.

    Comment

    • rowe_newsgroups

      #3
      Re: count occurances of digits in a string

      On Jun 27, 11:17 am, "Smokey Grindle" <nos...@nospam. comwrote:
      any fast way to do this? I just need to check if if a string which could
      have a lot of characters in it if it has numbers and count the number of
      numbers in the string. thanks!
      I thinking something like this:

      ' Assumes Imports System.Text.Reg ularExpressions

      Dim s As String = "Some string 454 with numbers in it. 4234"
      Dim regex As New Regex("\d")
      MsgBox(regex.Ma tches(s).Count)

      Thanks,

      Seth Rowe

      Comment

      Working...