[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 147
  • Last Modified:

Using the "Like" function

I want to search a string for the presence of another string.
SearchFor = "the"
I want to have the result work if the string contains exactly "the" if the characters are either upper case or lower case.
ie:
string Like (     )
I need the syntax in the (   ).
0
Lee5
Asked:
Lee5
1 Solution
 
rmichelsCommented:
The InStr function can search for the presence of one string in a larger string.

InStr(1,"asasfthe","the",vbTextCompare) will return 6, indication "the" begins at position 6.

The first parameter is the starting position to begin searching

The second param is the string to search

The third param is what you are searching for.

The last param is an optional one.  In the above example, search ignore case.
0
 
Erick37Commented:
Using the Like operator:

Dim str As String
str = "seArchThEstring"
If LCase(str) Like "*the*" Then
    Debug.Print "Found it!"
Else
    Debug.Print "Not found"
End If
0
 
amebaCommented:
Private Sub Form_Click()
    Dim str As String
    str = "seArchThEstring"
    If str Like "*[tT][hH][eE]*" Then
        Caption = "Found it!"
    Else
        Caption = "Not found"
    End If
End Sub
0
 
Lee5Author Commented:
Thanks for the more usable approach

Erick37 is also a good answer, but needs some UCase stuff.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now