compair lines

starcraft

Centurion
Joined
Jun 29, 2003
Messages
167
Location
Poway CA
i'm thining of making a command promt type program and i was wondering how do i compair a line the user just entered with a list of commands set into the program? i'd asume is something like
Visual Basic:
if richtextbox1.line = bob then
DO THIS![CODE=visualbasic] also if i did do that how could i set like a list of commands so i didn't have to set up an if equal for each command, just have like a list and it searchs the list.
 
You can use the equals method in string class to do this. If equals is used, it must be exact case (case sensitive).

If you want to create a list of lines that you can compare quick. Use Arraylist class to store your set of lines. Then when user type in something use method contains(String) to search for it.


Dim tArray as new ArrayList()

' Add your items here
tArray.Add("Your line")
tArray.Add("Another line")


' To find that the input line exist in your ArrayList
if tArray.contains("User Input")
Msgbox("Input exist")
else
Msgbox("Input not exist")


Hope that help.
 
you could always do the following , to find your text in a string / textbox :
Visual Basic:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim strString As String = "some StuFf In DifFeRenT CaSeS !"
        If Not strString.ToLower.IndexOf("stuff") = -1 Then
            MessageBox.Show("the word stuff was found in the string at position: " & strString.ToLower.IndexOf("stuff"))
        End If
    End Sub
you can do the same with TextBox or RichTextBox , eg:
Visual Basic:
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        TextBox1.Text = "some StuFf In DifFeRenT CaSeS !"
        If Not TextBox1.Text.ToLower.IndexOf("stuff") = -1 Then '/// make sure it's there or not.
            MessageBox.Show("the word stuff was found in the string at position: " & TextBox1.Text.ToLower.IndexOf("stuff"))
        End If
    End Sub
 
Use the Select Case statement


Select Case Command.ToUpper 'Or ToLower
Case "GET"
' Get something!
Case "SET"
' Set something!
End Select
 
Back
Top