I have textbox--
(texbox1)= aaa bbb ccc <e2>code</e2> aaa bbb ccc
just i want (textbox2)= I want the code between <e2> and </e2> the code
Where the code is a variable

Dim strS As String() = Nothing
            Dim actaulstring As String = ""
            strS = TextBox1.Text.Split(">")
            actaulstring = strS.GetValue(1)
            strS = actaulstring.Split("<")
            actaulstring = strS(0)

i am still newbie to vb.net, but had a general idea.. so i thought i will post

Dim tag1 As String = Textbox1.text.Replace("<e2>", "^")
        Dim tag2 As String = tag1.Replace("</e2>", "`")
        Dim Position1 As Integer = tag2.LastIndexOf("^") + 1
        Dim Position2 As Integer = tag2.LastIndexOf("`") - 1
        Dim code As String = tag2.Substring(Position1,Position2)

Edited 5 Years Ago by yoge911: color the code

"The best way to learn, is to help others." quoted from my experience.

Also, see if this helps to extract data from a String or .Text.

With TextBox1
            .Text = "aaa bbb ccc <e2>code</e2> aaa bbb ccc"
            Dim iStartIndex As Integer = .Text.IndexOf("<e2>") + 4 '// +4 to exclude the "<e2>" characters.
            '// .IndexOf(char./string to locate, Start search from this Index.)
            Dim iEndIndex As Integer = .Text.IndexOf("</e2>", iStartIndex)
            '// .Substring(Start Index of Substring, length of Substring to extract)
            TextBox2.Text = TextBox1.Text.Substring(iStartIndex, iEndIndex - iStartIndex) & "order :D"
        End With

Edited 5 Years Ago by codeorder: n/a

Not to beat a dead horse, but I'm surprised no one mentioned Regular Expressions

Imports System.Text.RegularExpressions

Module Module1
   Sub Main()
      Dim strTextBoxText As String = "asdf asdf <e2>code</e2> asdf asdf"
      Dim strCode As String = "Not Found"
      Dim rxE2 = New Regex("<e2>(?<target>.*)</e2>")
      If rxE2.IsMatch(strTextBoxText) Then
         strCode = rxE2.Match(strTextBoxText).Groups("target").Value
      End If
      ' ...and if this is a console test...
      ' Console.WriteLine(strCode)
   End Sub
End Module

Edited 5 Years Ago by thines01: clarity

This article has been dead for over six months. Start a new discussion instead.