TM80 TM80 - 1 year ago 74 Question Trying to get text between first and second slashs only

I am trying to retrive the value of the text between the first and second backslashes... but my coding skills have brought me this far and no futher.

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Dim splitted = TEST.Split("\"c)
Dim values = splitted.Skip(1).Take(splitted.Length - 2).ToArray()
End Sub

Answer Source

If you want "Two" as result, this should be the simplest approach:

Dim allToken As String() = "ONE\TWO\TRHREE\FOR\FIVE".Split("\"c)
Dim relevantPart = allToken.Skip(1).Take(1)
Dim result As String = String.Concat(relevantPart) ' "Two"

If you don't want a single string but a String() use ToArray:

Dim result As String() = relevantPart.ToArray()

Side-Note: you can't output an array directly, you could use String.Join:

MsgBox(String.Join(", ", result)) ' f.e. comma separated
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download