gimme4free
Elite Member
- Oct 22, 2008
- 1,935
- 1,989
I have 2 functions, 1 which I converted from PHP - VB that uses Regex (Requires System.Text.RegularExpressions). The other which was shared by a member on this site.
The problem that I am facing is that neither of the functions allow you to get the string between 2 escaped characters ("").
Function 1 (Regex):
Function 2:
Example string:
Neither of the above functions will find the 'findme' that it should be able to pull out whereas both functions will work on a simple string such as, "Hello Find Me World".
Also, I don't suppose that anyone here has a function that they wouldn't mind sharing that will find ALL occurences of a string between 2 strings and return in array format?
The problem that I am facing is that neither of the functions allow you to get the string between 2 escaped characters ("").
Function 1 (Regex):
Code:
Public Function GetStringBetween(ByVal Haystack As String, ByVal StartSearch As String, ByVal EndSearch As String) As String
Dim rx As New Regex(StartSearch & "(.+?)" & EndSearch)
Dim m As Match = rx.Match(Haystack)
If m.Success Then
Return m.Groups(1).ToString()
Else
Return False
End If
End Function
Function 2:
Code:
Public Function GetBetween(ByVal haystack As String, ByVal needle As String, ByVal needle_two As String) As String
Dim istart As Integer = InStr(haystack, needle)
If istart > 0 Then
Dim istop As Integer = InStr(istart, haystack, needle_two)
If istop > 0 Then
Try
Dim value As String = haystack.Substring(istart + Len(needle) - 1, istop - istart - Len(needle))
Return value
Catch ex As Exception
Return ""
End Try
End If
End If
Return ""
End Function
Example string:
Code:
Dim Haystack As String = "<input type=""hidden"" name=""testsubmit"" id=""testsubmit"" value=""findme"" />"
Dim FindIt As String = GetBetween(Haystack, "id=""testsubmit"" value=""", """ ")
MessageBox.Show(FindIt)
Neither of the above functions will find the 'findme' that it should be able to pull out whereas both functions will work on a simple string such as, "Hello Find Me World".
Also, I don't suppose that anyone here has a function that they wouldn't mind sharing that will find ALL occurences of a string between 2 strings and return in array format?