i have a string that looks like this:
sodjfoisdfsdf sdofij sodiosifosf fsdi a123 sdfoi sdofi osdi foi sdofd oi b123 sdfoijsfdoifsdiosfdoifsoifsdofjssfdoji
how do i extract everything from a123 to b123?
i have a string that looks like this:
sodjfoisdfsdf sdofij sodiosifosf fsdi a123 sdfoi sdofi osdi foi sdofd oi b123 sdfoijsfdoifsdiosfdoifsoifsdofjssfdoji
how do i extract everything from a123 to b123?
If your patterns are going to be as simple as a123
then simple string operations will suffice:
Dim s As String = "sodjfoisdfsdf sdofij sodiosifosf fsdi a123 sdfoi sdofi osdi foi sdofd oi b123 sdfoijsfdoifsdiosfdoifsoifsdofjssfdoji"
Dim startIndex As Integer = s.IndexOf("a123") + "a123".Length
Dim endIndex As Integer = s.IndexOf("b123")
Dim result = s.Substring(startIndex, endIndex - startIndex)
You can use the Text parsing functions to find the start and end position for your tokens.
For example:
Dim s As String = "sodjfoisdfsdf sdofij sodiosifosf fsdi a123 sdfoi sdofi osdi foi sdofd oi b123 sdfoijsfdoifsdiosfdoifsoifsdofjssfdoji"
Dim startToken As String = "a123"
Dim endToken As String = "b123"
Dim startTokenPosition As Integer = s.IndexOf(startToken)
Dim endTokenPosition As Integer = s.IndexOf(endToken)
'Validate both startToken and endToken were found...
Dim mysubstring As String = s.Substring(startTokenPosition + startToken.Length, endTokenPosition - startTokenPosition - startToken.Length)