user3362189 user3362189 - 3 months ago 13
Vb.net Question

VB.NET get between all strings one by one

so this code checks only once between

Private Function GetBetween(ByVal sSearch As String, ByVal sStart As String, _
ByVal sStop As String, Optional ByVal lSearch As Integer = 1) As String
Dim lTemp As Long

lSearch = InStr(lSearch, sSearch, sStart)
If lSearch > 0 Then
lSearch += Len(sStart)
lTemp = InStr(lSearch, sSearch, sStop)
If lTemp > lSearch Then
GetBetween = Trim(Mid(sSearch, lSearch, lTemp - lSearch))
End If
End If
End Function


i got this string the string is not stable i mean there can be more players then this http://pastebin.com/JTi51nBV and i want to show the text between player /player one by one for example in messagebox.
sorry for my english

Answer

Use the correct tool to parse XML, System.Xml.XmlDocument:

' Add the namespace at the top
Imports System.Xml
' And then ...
Dim sXml As String = "YOUR_XML_STRING_HERE"
Dim doc As New XmlDocument
doc.PreserveWhitespace = True
doc.LoadXml(sXml)
For Each Entry As XmlNode In doc.SelectNodes("//player")
    Console.WriteLine(Entry.InnerXml)
Next

See the VB.NET demo here.

If you do not need the tags to be shown, replace Entry.InnerXml with Entry.InnerText.

Note that the //player is an XPath expression that gets all <player> nodes.