Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Wildcard search in an array 1

Status
Not open for further replies.

mcpeekj

Vendor
Sep 21, 2001
105
0
0
I have a little loop that will search for a string inside of array elements. It works fine when I search for a string that is the entire element. But I need to search for a string inside of the element. How can I do a wildcard search? I've tried using %, * and ?, all to no avail. Doesn't appear I can use like and not like either.

Thoughts?

Code:
for j = 0 to alldatarows
	if (alldata(2,j)) = "?string i want?" then
		response.write "mystuff"
	exit for
	end if
next
 
Code:
for j = 0 to alldatarows
    if InStr(1, alldata(2,j), "string i want", vbTextCompare) > 0 Then
        response.write "mystuff"
        exit for
    end if
next

vbTextCompare will return case insensitive matches.

I was kinda bummed out though. When I first saw this question, I immediately thought of the Filter function. Unfortunately, it only works for 1 dimensional arrays. Since I put in the effort to make it work, I'm gonna post it anyway, because it may be useful later. [wink]

Code:
<%

    Dim arTemp
    Dim arMatch
    
    ' Make a 1 dimensional array of strings.
    arTemp = Split("Apple,Orange,Grape,Banana", ",")
    
    ' create another array for the results.
    ReDim arMatch(UBound(arTemp))
    
    ' run the filter function. 
    ' In this case....
    ' r is the string to match
    ' True means... return the matches.  False would return elements that do not match.
    ' vbTextCompare so we have a case insensitive search
    
    arMatch = Filter(arTemp, "r", True, vbTextCompare)
    
    ' display the results
    for i = lbound(arMatch) to ubound(arMatch)
      response.Write(armatch(i) & "<br />")
    next

%>

-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
Beautiful! Works like a charm.

Thanks George!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top