Access开发培训
网站公告
·Access专家课堂QQ群号:151711184    ·Access快速开发平台下载地址及教程    ·欢迎加入Access专家课堂微信群!    ·如何快速搜索本站文章|示例|资料    
您的位置: 首页 > 技术文章 > 源码示例

从字符串中取出夹杂的数字

时 间:2013-03-23 08:34:19
作 者:杜超-2号   ID:16058  城市:江阴
摘 要:还有第三种方法见相关文章
正 文:

点击下载此附件


'功能:从字符串中取出夹杂的数字
'方法一
'使用方法:GetNum([字段名称])
Function GetNum(Exp As String) As Double
    Dim lntI As Long
    Dim strWord As String

    For lntI = 1 To Len(Exp)
        strWord = Mid(Exp, lntI, 1)
            If strWord Like "[0-9]" Then
                GetNum = GetNum & strWord
            End If
    Next

End Function

'方法二
Function GetNum2(Exp As String) As Double
    Dim lntI As Long
    Dim strWord As String

    For lntI = 1 To Len(Exp)
        strWord = Mid(Exp, lntI, 1)
            If IsNumeric(strWord) Then
                GetNum2 = GetNum2 & strWord
            End If
    Next
End Function


方法三

Private Sub cmdok_Click()
Dim Str
Set re = CreateObject("VBScript.RegExp")
re.Global = True
re.IgnoreCase = True

Str = Me.txttest
re.Pattern = "\d{1,}"

Set Matches = re.Execute(Str)
For Each Match In Matches
   MsgBox Match.Value
Next
End Sub




Access软件网官方交流QQ群 (群号:483923997)       Access源码网店

常见问答:

技术分类:

相关资源:

专栏作家

关于我们 | 服务条款 | 在线投稿 | 友情链接 | 网站统计 | 网站帮助