Link to home
Start Free TrialLog in
Avatar of Matrix1000
Matrix1000

asked on

Need Help with parsing text in RichTextbox and putting items found into Treeview

I'd like to parse the contents of a RichTextBox and put the items that are found under the "All " parent node in a Treeview.

The text I'm looking for is in between the *_* markers for example:

*--*--*--*--*--*--*--*--*
 This is section #1 - This is what I want to put into the listbox.
*--*--*--*--*--*--*--*--*

Could someone help me out with the code for doing something like that?

Avatar of ZachSmith
ZachSmith
Flag of United States of America image


    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        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) + tag.Length
                endIndex = data.IndexOf(tag, startIndex)
 
                Me.TreeView1.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

Avatar of Matrix1000
Matrix1000

ASKER

Thanks!!!
Its almost working... If it finds one instance of the  *_*_* text its looking for it works great, but put two in there and it locks up the program and looks like the listbox scroll bars kind of go crazy like its a huge list.
e.g.

1. This works:

*--*--*--*--*--*--*--*--*
 This is section #1 - This is what I want to put into the listbox.
*--*--*--*--*--*--*--*--*

2. This doesn't:

*--*--*--*--*--*--*--*--*
 This is section #1 - This is what I want to put into the listbox.
*--*--*--*--*--*--*--*--*

*--*--*--*--*--*--*--*--*
 This is section #1 - This is what I want to put into the listbox.
*--*--*--*--*--*--*--*--*

end text

ASKER CERTIFIED SOLUTION
Avatar of ZachSmith
ZachSmith
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks Zach !!!
Really appreciate it!

If you're not to busy and want another 500 could you take a look at this question. I just need to put what it finds under the 'All' root node, instead of just under the plain root... see this for details.

https://www.experts-exchange.com/questions/23210833/How-to-place-text-in-a-specific-node-in-a-TreeView.html