The ST methods are certainly powerful and if you look at my suggested code above, I used another variation st.findBetweenPosition() which is similar but doesn’t return the string between - just the start and end positions:
and
perhaps a word about the check after the call is in order:
by default the returned positions exclude the start and end parameters and just give you what is between. If you wanted to include the start and end parameters there is a separate “Exclusive” parameter (which defaults to true) that you can set to false instead.
anyway in this case we are excluding the start and end parameters (the default…) so consider the string ‘abcdefg’
if we said between ‘b’ and ‘e’ then it would return 3 for start and 4 for end.
if we said between ‘b’ and ‘d’ then it would return 3 for start and 3 for end.
if we said between ‘b’ and ‘c’ then it would return 3 for start and 2 for end.
hence you can see why we check
if srcStart = 0 or srcStart > srcEnd
as that checks if the start/end parameters were found and also if there was any contents between them.