Select text between two keywords (advanced)

Hi I have text between the two keywords Start and End. However, it should only select text after the last Start and before the first End. E.g.:

“words
Start words
Start Get This
Text
End
End”

How can I have “Get This Text”?
Edit: It would also help if I could delete the first occurence of “Start”.

Hi @Jizh,

Try the below:

text.Substring((text.LastIndexOf(“Start”) +5), (text.IndexOf(“End”) - (text.LastIndexOf(“Start”) +5)))
Where text is you mentioned in the above post.

Regards,
Sasikumar

5 Likes

Here is the code :

Dim str As String = “words1 Start words Start Get This Text End End”

        If str.Contains("Start") = True Then

            Dim len As Integer = str.Length - (str.LastIndexOf("Start") + 5)
            str = str.Substring(str.LastIndexOf("Start") + 5, len)
            len = len - (str.IndexOf("End"))
            str = str.Remove(str.IndexOf("End"), len)
        End If
3 Likes

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.