SMid - "Smart" Mid
This function is similar to the Mid function. Except, you can specify the starting, and ending strings (capture the data in between).
Original Author: Derek de Oliveira
Inputs
orig_string As String : Source string
start As Long : Location in source to start from
str_start As String : beginning string (capture from)
str_end As String : ending string (capture to)
Returns
This code will return the data that is found between the "str_start" and "str_end" strings.
Code
'Example:
'newStr = SMid("Hello 1Between2 world!", 1, "1", "2")
'will return: "Between"
Function SMid(orig_string As String, start As Long, str_start As String, str_end As String)
On Error GoTo handler
'SMid (Smart MID)
'By: Derek de Oliveira
'Use this function in any program. No need to thank me :)
'o_string = Origional String
's_start = Start From string
's_end = Ending string
step1 = InStr(start, orig_string, str_start, vbTextCompare)
result = Mid(orig_string, step1 + Len(str_start), InStr(step1 + Len(str_start), orig_string, str_end, vbTextCompare) - step1 - Len(str_start))
SMid = result
Exit Function
handler:
SMid = ""
End Function
Loading Comments ...
Comments
No comments have been added for this post.
You must be logged in to make a comment.