|
本帖最后由 xuwenning 于 2017-5-5 15:20 编辑
借roych的花献给大家
'获取第N个和N+1个分隔符之间的字符串【模块】
'调用说明:
'call getText(strInput ,strSperator , lngNum)
'参数说明:
'strInput————————————————————输入字符串
'strSperator——————————————————分隔符
'lngNum—————————————————————第几个分隔符
'例如:
'getText("123456-123456-123-789-456", "-", 3)
''返回第三个分隔符(-)与第四个分割符之间的字符串:789
Function getText(ByVal strInput As String, ByVal strSperator As String, ByVal lngNum As Long) As String
Dim i As Long
Dim k As Long
Dim j As Long
Dim h As Long
For i = 1 To Len(strInput)
If Mid(strInput, i, 1) = strSperator Then
k = k + 1
If k = lngNum Then j = i
If k = lngNum + 1 Then
h = i
Exit For
End If
End If
Next
If j > 0 Then
getText = Mid(strInput, j + 1, h - j - 1)
Else
MsgBox "没有符合要求的字符串"
getText = ""
End If
End Function |
|