Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

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.

Posted

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.

  • Leaders
Posted

you could always do the following , to find your text in a string / textbox :

   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:

   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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...