• Welcome to Valhalla Legends Archive.
 

WildCards

Started by ILurker, March 16, 2003, 06:33 PM

Previous topic - Next topic

ILurker

What is an easy way to use wildcards?
 "/ban *[aC]"

Noodlez

#1
by writing a wildcard matching function

but, since im pretty sure your not capable of that use Like

example:
dim str1 as string, str2 as string
str1 = "ilurker thinks noodlez is stupid and look here he goes helping him!"
str2 = "*stupid*"
if lcase(str1) like lcase(str2) then
msgbox "str1 matches str2"
end if

Coltz

#2
another way to do it, though not the best, would be to use the vbtextcompare function.

Camel

#3
Dim Statement As String, MatchItTo As String
Statement = "This is my statement!"
MatchItTo = "This*statement!"
If Statement Like MatchItTo Then
    ...
End If

go through a loop for each user in your listview or whatever, and use: If UserName Like "*[aC]" Then
if you want it to be case insensitive (very good idea, expecially for usernames): If LCase(UserName) Like LCase("*[aC]") Then

Mesiah / haiseM

i dont know where i got this but it could be of some assistance:

Public Function Match(ByVal username As String, ByVal Matcher As String) As Boolean
Match = False
    Dim Args() As String, Jd As Long
        Args() = Split(username, "*")
        If (Left$(username, 1) = "*") And (Right$(username, 1) = "*") Then
            For Jd = 0 To UBound(Args)
                If Args(Jd) <> "" Then
                    If InStr(1, LCase(Match), LCase(Args(Jd))) = 0 Then
                        Exit Function
                    End If
                End If
            Next Jd
            Match = True
        End If
End Function
]HighBrow Innovations
Coming soon...

AIM Online Status: 

Etheran

#5
Perhaps you should look into regex. (surprised nobody brought that up)

Grok

#6
VB has a LIKE operator.  You may wish to use MSDN Online.

Spht

#7
I wouldn't suggest using Visual Basic's LIKE operator, as is, for wildcard matching of Battle.net usernames. LIKE sees [ ] # characters as special wildcard characters which could confuse things when comparing names on Battle.net since those are valid characters for Battle.net usernames. If you're not following, try comparing *[vL]* to Spht-vL: "Spht-vL" Like "*[vL]*" - that statement would be TRUE for a Visual Basic LIKE compare when it should be FALSE with ordinary wildcard matching (RegEx, I believe).

As Grok suggested, you should check MSDN for more information.

Skywing

#8
QuoteI wouldn't suggest using Visual Basic's LIKE operator, as is, for wildcard matching of Battle.net usernames. LIKE sees [ ] # characters as special wildcard characters which could confuse things when comparing names on Battle.net since those are valid characters for Battle.net usernames. If you're not following, try comparing *[vL]* to Spht-vL: "Spht-vL" Like "*[vL]*" - that statement would be TRUE for a Visual Basic LIKE compare when it should be FALSE with ordinary wildcard matching (RegEx, I believe).

As Grok suggested, you should check MSDN for more information.
Not quite - VB's LIKE supports (some) real RegEx, while just wildcard matching is only a subset of that.

dxoigmn

#9
QuoteMSDN: Note   To match the special characters left bracket ([), question mark (?), number sign (#), and asterisk (*), enclose them in brackets. The right bracket (]) can't be used within a group to match itself, but it can be used outside a group as an individual character.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vblr7/html/vaoprlike.asp

MrRaza

#10
I found this on my computer, edit it to do want you want.

Private b1() As Byte
Private b2() As Byte


Public Function Simil(String1 As String, String2 As String) As Double
   Dim l1 As Long
   Dim l2 As Long
   Dim l As Long
   Dim r As Double


   If UCase(String1) = UCase(String2) Then
       r = 1
   Else
       l1 = Len(String1)
       l2 = Len(String2)


       If l1 = 0 Or l2 = 0 Then
           r = 0
       Else
           ReDim b1(1 To l1): ReDim b2(1 To l2)


           For l = 1 To l1
               b1(l) = Asc(UCase(Mid(String1, l, 1)))
           Next


           For l = 1 To l2
               b2(l) = Asc(UCase(Mid(String2, l, 1)))
           Next
           r = SubSim(1, l1, 1, l2) / (l1 + l2) * 2
       End If
   End If
   Simil = r
   Erase b1
   Erase b2
End Function


Private Function SubSim(st1 As Long, end1 As Long, st2 As Long, end2 As Long) As Long
   Dim c1 As Long
   Dim c2 As Long
   Dim ns1 As Long
   Dim ns2 As Long
   Dim i As Long
   Dim max As Long
   If st1 > end1 Or st2 > end2 Or st1 <= 0 Or st2 <= 0 Then Exit Function


   For c1 = st1 To end1


       For c2 = st2 To end2
           i = 0


           Do Until b1(c1 + i) <> b2(c2 + i)
               i = i + 1


               If i > max Then
                   ns1 = c1
                   ns2 = c2
                   max = i
               End If
               If c1 + i > end1 Or c2 + i > end2 Then Exit Do
           Loop
       Next
   Next
   max = max + SubSim(ns1 + max, end1, ns2 + max, end2)
   max = max + SubSim(st1, ns1 - 1, st2, ns2 - 1)


SubSim = max
End Function


Inputs: mainstring and checkstring, the
    2 strings to compare

Returns: how similar the 2 strings are
    (percent, as in .8)

Assumes: This code recursively loops
    through the 2 strings, finding the largest
    common substring, then checking the
    remainder of the string.