有形如“容量,PR450MAH”的数字,我想把中间的450取出来,有没有直接能够实现这个功能的函数?
用RIGHT加INSTR也可以实现,但我想得到更普遍的做法。

解决方案 »

  1.   

    对字符串中每个字符的ASCII码进行判断,然后取出需要的数据
      

  2.   

    Dim Nstr As String
    Private Sub Command1_Click()
     Nstr = "111asdfe@#$#@45123434532asdf"
     ChNum Nstr
     MsgBox Nstr
    End SubPublic Function ChNum(sStr As String)
     Dim mStr As String
     For i = 1 To Len(sStr)
      If Asc(Mid(sStr, i, 1)) > 47 And Asc(Mid(sStr, i, 1)) < 58 Then mStr = mStr + Mid(sStr, i, 1)
     Next i
     sStr = mStr
    End Function
      

  3.   

    Private Sub Command1_Click()
        StringLoginLock "容量,PR450MAH"
    End Sub
    Public Function StringLoginLock(ByVal strid As String)
          Dim charsInFile As Integer
          Dim i As Integer
          Dim j As Integer
          Dim Letter As String
          Dim StrLogin As String
          'Dim Strstart As String
          Dim Stra As String
            charsInFile = Len(Trim(strid))
            For i% = 1 To charsInFile
                Letter$ = Mid(strid, i%, 1)
                 j = Asc(Letter)
                 If j >= 48 And j <= 57 Then
                       StrLogin = StrLogin & CStr(Letter)
                 End If
            Next i%
            
            MsgBox StrLogin
    End Function