[AccessD] instr() - Need an exact match

Heenan, Lambert Lambert.Heenan at AIG.com
Thu Sep 11 16:18:47 CDT 2003


I see what you mean now. Here's some code to do the trick. I've done SOME
testing and it seems to work just fine...


Function exactInstr(strTarget As String, strFind As String, Optional
nCompareType As Integer = vbTextCompare) As Long
Dim nFoundLocation As Long
    nFoundLocation = InStr(1, strTarget, strFind, nCompareType)
    If nFoundLocation > 0 Then
        If nFoundLocation + Len(strFind) = Len(strTarget) Then ' found the
whole string at the end of the target
            exactInstr = nFoundLocation
        Else
            If nFoundLocation > 1 Then
                ' check the characters to the left and right of the target
string
                If isDelimiter(Mid(strTarget, nFoundLocation - 1, 1)) Then
                    If isDelimiter(Mid(strTarget, nFoundLocation +
Len(strFind), 1)) Then
                        exactInstr = nFoundLocation
                    Else
                        exactInstr = 0
                    End If
                Else
                    exactInstr = 0
                End If
                    
            Else ' strFind is at the start of the target
                If isDelimiter(Mid(strTarget, nFoundLocation + Len(strFind),
1)) Then
                    exactInstr = nFoundLocation
                Else
                    exactInstr = 0
                End If
            End If
        End If
    Else
        exactInstr = 0
    End If
End Function

Function isDelimiter(strC As String) As Boolean
Const AllowedDelimiters = ", " ' That's a Comma and a space inside the
quotes.
    isDelimiter = InStr(AllowedDelimiters, strC) > 0
End Function


Lambert

> -----Original Message-----
> From:	John Skolits [SMTP:askolits at ot.com]
> Sent:	Thursday, September 11, 2003 4:36 PM
> To:	Access Developers discussion and problem solving
> Subject:	RE: [AccessD] instr() - Need an exact match
> 
> Here is a better example. In this case both function return a 1
> 
> 
> StrComp("SecGrp_Eng_Super, secGrp_Admin", "SecGrp_Eng_Super")
> 
> 
> StrComp("SecGrp_Eng_Super, secGrp_Admin", "SecGrp_Eng")
> 
> The first one is an exact match, the second a partial match. I want to
> distinguish between the two.
> 
> 
> 
> 
> 
> -----Original Message-----
> From: accessd-bounces at databaseadvisors.com
> [mailto:accessd-bounces at databaseadvisors.com]On Behalf Of Heenan,
> Lambert
> Sent: Thursday, September 11, 2003 4:13 PM
> To: 'Access Developers discussion and problem solving'
> Subject: RE: [AccessD] instr() - Need an exact match
> 
> 
> I'm not clear on why InStr() does not suit your purpose.
> 
> InStr("a_Group,b_Group,c_Group","c_Group") will return a non-zero value
> (17), meaning that "c_Group" was found in the first string. Now if you
> want
> an exact match that takes the case into account you can use...
> 
> InStr(1,"a_Group,b_Group,c_Group","c_group",vbBinaryCompare)  ' note, must
> supply the start position - 1
> 
> which will return zero as "c_group" is not found, whereas
> 
> InStr(1,"a_Group,b_Group,c_Group","c_Group",vbBinaryCompare)
> 
> returns 17.
> 
> Lambert
> 
> > -----Original Message-----
> > From:	John Skolits [SMTP:askolits at ot.com]
> > Sent:	Thursday, September 11, 2003 3:54 PM
> > To:	Access Developers discussion and problem solving
> > Subject:	[AccessD] instr() - Need an exact match
> >
> > Is there a way to do an exact match with something like Instr(). I don't
> > want a partial match.
> >
> > For example:
> > I have a string:    "SecGrp_Admin, SecGrp_Eng, SecGro_User"
> >
> > I want to look see if "SecGrpAdmin_Super" is in the string. Instr() will
> > return a value but I want an exact match.
> >
> > I know I can parse the string and look for an exact match based on the
> > parsed value. I just thought maybe there's a function I can use that
> would
> > do an Exact match test.
> >
> > John Skolits
> >
> >
> >
> >
> > _______________________________________________
> > AccessD mailing list
> > AccessD at databaseadvisors.com
> > http://databaseadvisors.com/mailman/listinfo/accessd
> > Website: http://www.databaseadvisors.com
> _______________________________________________
> AccessD mailing list
> AccessD at databaseadvisors.com
> http://databaseadvisors.com/mailman/listinfo/accessd
> Website: http://www.databaseadvisors.com
> 
> _______________________________________________
> AccessD mailing list
> AccessD at databaseadvisors.com
> http://databaseadvisors.com/mailman/listinfo/accessd
> Website: http://www.databaseadvisors.com


More information about the AccessD mailing list