VBA, MS Access MS Access в примерах

Часть строки между заданнами образцами текста

Private Function GetStringBetweenStrings(StringToBeSeached As String, StartString As String, EndString As String)
'Возвращает часть строки между заданнами образцами   
    Dim StartPos As Long
    Dim EndPos As Long
   
    StartPos = InStr(1, StringToBeSeached, StartString) + Len(StartString)
    EndPos = InStr(StartPos, StringToBeSeached, EndString)
   
    GetStringBetweenStrings = Mid(StringToBeSeached, StartPos, EndPos - StartPos)
   
End Function


Пример эксплуотации:

Private Sub Test_001()
Dim strMailMessage As String
Dim strRes As String
    
    strMailMessage = "Bla - Bla - Bla " & vbCrLf & vbCrLf & vbCrLf & "First name:" & _
        vbCrLf & vbCrLf & "Phil" & vbCrLf & "GOGO" & vbCrLf & vbCrLf & "Last name:"
    'Debug.Print strMailMessage
    strRes = Replace(GetStringBetweenStrings(strMailMessage, "First name:", "Last name:"), vbCrLf, " ")
    strRes = Replace(Trim(strRes), "  ", " ")
    Debug.Print strRes
End Sub
Назад ToTop
L.E. 21.09.2023
Рейтинг@Mail.ru