VBA(函数) 文本中截取指定开始字符指定长度字符串

Function CutR(str As String, endStr As String, getLen As Integer) As String

'CutR函数
'截取文本中指定开始字符,指定长度的字符串,如截取编号等
'str: 文本
'endStr: 目标字符串 , 或者编号的标识符
'getLen: 要截取的长度
'返回值:  指定长度的字符

Dim e As Integer
    e = InStr(str, endStr) + Len(endStr)

    If e < 0 Then
        CutR = ""
    Else
        CutR = Mid(str, e, getLen)
    End If
    
End Function

 '测试 得到36个字符长度的  45706EC7-5B31-48FD-A75D-00005A08C27D

Sub test()
Dim str As String
    str = CutR("sadlaskdajdkajkGuidNo:45706EC7-5B31-48FD-A75D-00005A08C27D********", "GuidNo:", 36)
    Debug.Print str
    Debug.Print Len(str)
End Sub

猜你喜欢

转载自www.cnblogs.com/zdln-kc003/p/11981358.html