[VB6] Find all occurrences of two strings and what's between them.

[Dragoon]

Vortigaunt
Joined
Feb 27, 2004
Messages
840
Reaction score
6
Not Half-life related, but I figured this would still be the best place to post this question.

How would I find all occurrences of two strings (string1, and string2), and what's between each set of occurrences?

For example, if string1 = "X" and string2 = "Z" and I ran it on the following text:

Code:
lololol X1Z text
other text XabcZ more text
XyZ etc

I want it to return "1", "abc", and "y".

Anyone know how to do this?
 
You could simply use substrings. Read each string one letter at a time, when you find X then keep on reading them one at a time except record them into a new string until you find Z or the string ends.

I don't work with VB although this should be perfectly possible.
 
Yep, that's one of the easy ways to do it. Another way would be through the Instr function. Get the positions of string1 and string2 in text through Instr, and use Mid to get what's in between, move to the next occurences of string1 and string2...
 
Back
Top