Link to home
Create AccountLog in
Avatar of Matrix1000
Matrix1000

asked on

How to parse a richtextbox for specific text and write 'found message' line to listbox?

I've got a richtextbox on a form along with a listbox. ( using MDI forms)
The listbox has 4 columns.

I'm trying to parse the text and find specific stuff after I load a text file. I'd like to add the functionality where I can make an entry in the Listbox like "Category, Error Message, Line#"

e.g. If "SpecificText" is found, ListView1.Item.Add("Severe", This error is severe and why, Line# 1234")

I've attached my Parsing code... How could I fit in some code into it to do something like that
Public Sub LoadListbox()
        Dim ChildFormListBox As frmMainChildForm = CType(Me.ActiveMdiChild, frmMainChildForm)
        Dim data As String = ChildFormListBox.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())
 
                ChildFormListBox.tvMainJumpMenu.Nodes("All").Nodes.Add(data.Substring(startIndex, endIndex - startIndex).Trim().Replace("(  ", "").Replace(" )", ""))
                lastIndex = endIndex + tag.Length
            Else
                KeepGoing = False
            End If
        End While
    End Sub

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of ZachSmith
ZachSmith
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
Avatar of Matrix1000
Matrix1000

ASKER

Thanks Zach!

Thats great.
Can you answer this regarding this parsing structure for another 500?

https://www.experts-exchange.com/questions/23227019/Parsing-text-what-is-the-correct-syntax-for-this.html