Hasnaad Din Hasnaad Din - 1 year ago 73
Vb.net Question

How to split a string containing {hello}{world} curley brackets but keep the brackets (vb.net)

I'm trying to find a way of splitting a string that contains 2 {}{} brackets but after it's split it keeps the brackets.

Before word = {XXXX}{XXXX}


  • Word(1) = {XXXX}

  • word(2) = {XXXX}

I tried using split but this always removes the }{ which I want to keep. Somebody get me out of my misery!! I'm using vb.net.

Dim word As String = "{hello}{world}"
Dim wordArr As String() = word.Split("}")

Answer Source

This will work:

Dim word As String = "{hello}{world}"
    Dim wordArr As String() = word.Split({"}"}, StringSplitOptions.RemoveEmptyEntries)
    Dim lst1 As New List(Of String)
    For Each l In wordArr
        lst1.Add(l & "}")
    wordArr = lst1.ToArray
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download