README.md
December 4, 2022 ยท View on GitHub
Description
This code will search a string for a given starting point(strFind) and a given end point(strSentinel) and return all the text in between. You can also add to the length of the start point if you don't want to include a number of unknown characters in the result
More Info
| Submitted On | |
| By | Peter B |
| Level | Beginner |
| User Rating | 4.0 (8 globes from 2 users) |
| Compatibility | VB 6.0 |
| Category | String Manipulation |
| World | Visual Basic |
| Archive File |
Source Code
Function ExtractString(ByVal strText As String, _
strFind As String, _
intAddToLen As Integer, _
strSentinel As String, _
TrapErrors As Boolean, _
intLength As Integer) As String
Dim SStart As Integer
Dim SEnd As Integer
SStart = InStr(1, strText, strFind) + Len(strFind) + intAddToLen
If SStart <= Len(strFind) And TrapErrors = True Then
MsgBox """" & strFind & """ not found!", vbCritical, "Error"
Exit Function
End If
SEnd = InStr(SStart, strText, strSentinel)
If SEnd <= Len(strFind) And TrapErrors = True Then
MsgBox "Sentinel value """ & strSentinel & """ not found!", vbCritical, "Error"
Exit Function
End If
If intLength > 0 Then
ExtractString = Mid(strText, SStart, intLength)
Else
ExtractString = Mid(strText, SStart, (SEnd - SStart))
End If
End Function