0

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?

4
Contributors
3
Replies
5
Views
6 Years
Discussion Span
Last Post by Mariandi
0
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
0

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
0

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")

Edited by Mariandi: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.