vb.net get string between two strings code example

Example: vb.net get string between two strings

Public Function GetStringBetween(ByVal InputText As String, ByVal starttext As String, ByVal endtext As String)
  Dim startPos As Integer
  Dim endPos As Integer
  Dim lenStart As Integer
  startPos = InputText.IndexOf(starttext, StringComparison.CurrentCultureIgnoreCase)
  If startPos >= 0 Then
    lenStart = startPos + starttext.Length
    endPos = InputText.IndexOf(endtext, lenStart, StringComparison.CurrentCultureIgnoreCase)
    If endPos >= 0 Then
      Return InputText.Substring(lenStart, endPos - lenStart)
    End If
  End If
  Return "ERROR"
End Function

Tags:

Vb Example