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

查找字符串的两个函数

时 间:2014-11-07 23:41:24
作 者:在水一方   ID:20576  城市:沈阳
摘 要:查找字符串中某个字段的函数
正 文:

 ’1.不使用数组

Function RightStr(inputstr, insplit, I) As String   '字符串,分隔符,字段所在节
    Dim z, l, k As Integer
    Dim x As String
    inputstr = inputstr & insplit
    k = Len(inputstr)
    For m = 1 To k
        x = Mid(inputstr, m, 1)
        If x = insplit Then
            z = z + 1
            If z = I - 1 Then 'MsgBox l, , "开始位置l"
                l = m
            ElseIf z = I Then 'MsgBox k, , "结束位置k"
                k = m
            End If
        End If
    Next
    RightStr = Mid(inputstr, l + 1, k - l - 1)

End Function


‘2. 利用数组的方法
Function RightStr2(inputstr, insplit, I) As String '字符串,分隔符,字段所在节
    Dim z(100), f(100)
    z(100) = f(100)
    m = InStr(inputstr, insplit)
    Do While m > 0
        xstr = Left(inputstr, m - 1)
        k = k + 1
        z(k) = xstr
        inputstr = Mid(inputstr, m + 1)
        m = InStr(inputstr, insplit)
    Loop
    RightStr2 = z(I)
End Function


Private Sub Command8_Click()
    On Error GoTo err:
    Dim inputs, ins As String
    Dim pos As Integer
    inputs = Me.inputs
    ins = Me.ins
    pos = Me.pos
    ' Me.outputstr = RightStr(inputs, ins, pos)
    Me.outputstr = RightStr2(inputs, ins, pos)
err:
End Sub

 
附   件:

点击下载此附件



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

常见问答:

技术分类:

相关资源:

专栏作家

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