Find string and compare in richtext box

Toshiba Satellite l505d-s5965 notebook
April 14, 2013 at 19:36:56
Specs: Windows 7, 1024

I have a richtextbox with strings

example

string1 bah bah bah 4
string2 bah bah bah 2
sting 3 bah bah bah 4
string1 bah bah bah 6


what I need help with is when reading a line by line whats the best way to find "String1" then compare is the number is greater or lower and place those in a usable variable if string is found multiple times

kinda like var1 is this and var 2 is this and so on.


See More: Find string and compare in richtext box

Report •

#1
April 14, 2013 at 20:17:14
[T]he number is greater or lower . . . as compared to what?

How To Ask Questions The Smart Way


Report •

#2
April 14, 2013 at 20:21:07
compare the "4" in this line in the example

string1 bah bah bah 4

now the "4" might be different. not static if that makes sense.


thank you for the reply. :)


EDIT: I'm comparing the String1 with the Numbers that are in the line to be compared. so when I read line by line and find two or more strings1 in the textbox then place each "string1 and the Number in a Variable.


Report •

#3
April 15, 2013 at 09:43:38
You're still bad at explaining what you want to do, but I don't care. This should get you started.
Function GetElements(ByRef searchStr As String, ByRef searchFrom As String) _
As List(Of String)
    Dim lst = New List(Of String)()
    Dim lines = searchFrom.Split({vbCr, vbLf},
                                 StringSplitOptions.RemoveEmptyEntries)
    For Each line In lines
        Dim tokens = line.Split()
        If tokens.Count > 1 AndAlso tokens(0) = searchStr Then _
            lst.Add(tokens.Last)
    Next
    Return lst
End Function

 . . . . . . . . . . . . . .
'Elsewhere . . . 
Dim foo = GetElements("string1", rtb.Text)

How To Ask Questions The Smart Way


Report •
Related Solutions


Ask Question