ExtensionMethod.NET Home of 875 C#, Visual Basic, F# and Javascript extension methods

Extract

Extract string from a string

Source

<Extension()> _
Public Function Extract(ByVal value As String, ByVal strStart As String, ByVal strEnd As String) As String
    If Not String.IsNullOrEmpty(value) Then
        Dim i As Integer = value.IndexOf(strStart)
        Dim j As Integer = value.IndexOf(strEnd)
        Return value.Substring(i, j - i)
    Else
        Return value
    End If
End Function

Example

Textbox1.Text = "This is a test. Can you pass?"

Textbox1.Text.Extract("This","test")

Author: NetDorkie

Submitted on: 16 jul 2009

Language: VB

Type: System.String

Views: 4364