如比一个STRING : 请说出以下的一些数字 586854654我就要取这个 586854654 ,数字是不固定的,位置也不固定

解决方案 »

  1.   

    用正则有点杀鸡用牛刀了。
    dim thestring as string
    thestring="请说出以下的一些数字 586854654"
    dim digits as string
    digits=""
    dim i as long
    for i=0 to len(thestring)
      if isnumeric(mid$(thestring,i,1)) then
        digits=digits & mid$(thestring,i,1)
      else
        if len(digits)<>0 then
          '截获了一个数字
          Me.Print digits
          digits=""
        end if
      end if
    next
      

  2.   

    if isnumeric(mid$(thestring,i,1)) then 编译不通过
      

  3.   


    Private Sub Form_Load()
        Dim thestring As String
        thestring = "请说出以下的一些数字 586854654"
        Dim digits As String
        digits = ""
        Dim i As Long
        For i = 1 To Len(thestring)
            If IsNumeric(Mid$(thestring, i, 1)) Then
                digits = digits & Mid$(thestring, i, 1)
            Else
                ProcDigits digits
            End If
        Next
        ProcDigits digits
    End SubPrivate Sub ProcDigits(ByRef digits)
        If Len(digits) <> 0 Then
            '截获了一个数字
            Debug.Print digits
            digits = ""
        End If
    End Sub