Find "-****-" within a string, where each star represents an integer (0 to 9) in VBA -


my brain struggling bit right , i'm trying accomplish said in title. reiterate, if have arbitrary string , want find position of 4 consecutive numbers (of integer value between 0 , 9), separated 2 "-", need find "-****-" each "*" represents integer between 0 , 9. ideal return value of function position of first "-".

what have tried far, returns integers within arbitrary string. haven't been able farther this.

function onlydigits(s string) integer     dim retval string    ' return string.      '     dim integer        ' counter character position. '     dim firstdashposition integer     dim founddash boolean     founddash = false     firstdashposition = 0      debug.print s     retval = ""      = 1 len(s)         if mid(s, i, 1) "-"             if founddash = true                 retval = retval + "-"                 firstdashposition =                 onlydigits = firstdashposition - 6                 exit function             end if              debug.print "here"             founddash = true             retval = retval + "-"         elseif mid(s, i, 1) >= "0" , mid(s, i, 1) <= "9" , founddash = true             retval = retval + mid(s, i, 1)         else             founddash = false             retval = ""         end if     next     onlydigits = firstdashposition end function 

regular expressions might better solution simple 1 time solution

function onlydigits(s string) integer      dim integer     = 1 len(s)          if mid$(s, 1, 6) "-[0-9][0-9][0-9][0-9]-"            onlydigits =            exit function         endif     next      onlydigits = -1  end function 

Comments

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -