user6069814
user6069814

Reputation:

I want to use asterisk as wildcard

Following code is okey.

    If Label1.Text = "WELCOME HOME" Then
        MsgBox("Hello")
    End If

Following code is not okey. (I want to use asterisk as wildcard)

    If Label1.Text = "*WELCOME HOME*" Then
        MsgBox("Hello")
    End If

Any idea?

Upvotes: 0

Views: 94

Answers (1)

Lennart
Lennart

Reputation: 10343

Comparing strings doesn't work that way, you should use the Contains() function:

 If Label1.Text.Contains("WELCOME HOME") Then
        MsgBox("Hello")
 End If

The equality check should be done with the Equals() method. Comparison with = actually works in VB.Net, but I think it is less clear and might be mistaken for an assignment.

If Label1.Text.Equals("WELCOME HOME") Then
            MsgBox("Hello")
End If

Upvotes: 1

Related Questions