Link to home
Create AccountLog in
Avatar of Matrix1000
Matrix1000

asked on

How to Trim "(" and " )" from text.

I have a snippit of code that parses a text file and pulls out some text. Then I put it into a treeview.

The problem is that sometimes some of the text has brackets around it.
e.g.
*_*_*_*_*_*_*_*_*_*_*_*
 ( the text I want)
*_*_*_*_*_*_*_*_*_*_*_*

I want to get rid of the brackets. How can I modify the attached code to remove them?
Private Sub LoadListbox()
        Dim data As String = Me.RichTextBox1.Text
        Dim KeepGoing As Boolean = True
        Dim lastIndex As Integer = 0
        Dim tag As String = "*--*--*--*--*--*--*--*--*"
 
        While KeepGoing
            If data.IndexOf(tag, lastIndex) > -1 Then
                Dim startIndex As Integer
                Dim endIndex As Integer
 
                startIndex = data.IndexOf(tag, lastIndex) + tag.Length
                endIndex = data.IndexOf(tag, startIndex)
 
                'Me.TreeView1.Nodes.Add(data.Substring(startIndex, endIndex - startIndex).Trim())
                Me.TreeView1.Nodes("All").Nodes.Add(data.Substring(startIndex, endIndex - startIndex).Trim())
 
                lastIndex = endIndex + tag.Length
            Else
                KeepGoing = False
            End If
        End While
    End Sub

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of appari
appari
Flag of India image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
SOLUTION
Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Got me! :) I missed the replace parameter in my code anyway.
SOLUTION
Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account