VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



SMid Smart Mid

by Derek de Oliveira (1 Submission)
Category: VB function enhancement
Compatability: Visual Basic 3.0
Difficulty: Beginner
Date Added: Wed 3rd February 2021
Rating: (2 Votes)

This function is similar to the Mid function. Except, you can specify the starting, and ending strings (capture the data in between).

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)
Code Returns
This code will return the data that is found between the "str_start" and "str_end" strings.

Rate SMid Smart Mid

'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

Download this snippet    Add to My Saved Code

SMid Smart Mid Comments

No comments have been posted about SMid Smart Mid. Why not be the first to post a comment about SMid Smart Mid.

Post your comment

Subject:
Message:
0/1000 characters