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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM