how to check if the user input has a match in my given string

Dim a as string

a = "abc"

if the user input in the textbox "erty" the message box will be shown string not found. if the user input 123abc the message box will be string found. how to do that?

Recommended Answers

All 3 Replies

Dim userString as string
dim ActualString as string="123abc"
userString =textbox1.text
If userstring=actualstring then
messagebox.show("String Found")
Else
messagebox.show("String not Found")

End IF

You can do it more appropriate with creating its own method, and call it from your main one:

Private Sub MyMethod()
	Dim toCheck As String = "someValue"
	Dim bChecking As Boolean = Checking(textBox1.Text, toCheck)
	If bChecking Then
		MessageBox.Show("Values are equal.")
	Else
		MessageBox.Show("Values are different.")
	End If
End Sub

Private Shared Function Checking(input As String, toCheck As String) As Boolean
	Return If(input.Equals(toCheck), True, False)
End Function

If understand correctly you need to identify if 'abc' is part of the inserted string.
this can be done be using the existing functions of vb.net like this

Dim SearchString as string ="abc"
Dim userstring As string= textBox1.Text

If userstring.contains(SearchString) then
messagebox.show("String Found")
Else
messagebox.show("String not Found")

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.