Re: Search Ambiguous
- From: "Tony Proctor" <tony_proctor@xxxxxxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Sat, 23 Aug 2008 18:29:36 +0100
Too simplistic I'm afraid Rick
Suppose the pattern has multiple instances of '*', e.g.
<frag1>*<frag2>*<frag3>, and/or occurrences of ?/#.
The starting point for matching frag2 depends on the accuracy of the match
for the next *<frag3>, and so on down the string. It cannot be done without
recursion or some internal stack remembering the current guess for the
starting point of each '*'
Also, it only returns one text fragment as opposed to some array of
fragments matching each of the wildcard characters
Tony Proctor
"Rick Rothstein (MVP - VB)" <rick.newsNO.SPAM@xxxxxxxxxxxxxxxxxx> wrote in
message news:%23JDtIyTBJHA.4724@xxxxxxxxxxxxxxxxxxxxxxx
What about this modification to the function I posted earlier in this
thread? I *think* it does what you are saying without needing recursion...
Function AmbiguousFindAndReturn(TextString As String, _
Pattern As String) As String
Dim X As Long
Dim Z As Long
Dim Location As Long
Do While Left(Pattern, 1) = "*"
Pattern = Mid(Pattern, 2)
Loop
For X = 1 To Len(TextString)
If Mid(TextString, X) Like Pattern & "*" Then
Location = X
For Z = 1 To Len(TextString) - Location + 1
If Mid(TextString, Location, Z) Like Pattern & "*" Then
AmbiguousFindAndReturn = Mid(TextString, Location, Z)
Exit Function
End If
Next
End If
Next
End Function
Rick
"Tony Proctor" <tony_proctor@xxxxxxxxxxxxxxxxxxxxxxxxxxxxx> wrote in
message news:O1ZHU1RBJHA.1184@xxxxxxxxxxxxxxxxxxxxxxx
Are you interested at all in identifying the actual text matching the
wildcard markers Lorin? For instance, given a pattern of "Today is *. The
time is ##:##" and a string of "Today is Saturday. The time is 13:35",
something that would give you the "Saturday", the "13" and the "35".
I needed to do this a while back for a regression-test suite and couldn't
find anything that did what I wanted. I eventually wrote something
myself. It was an interesting recursive problem since the new starting
point after a "*" depends on the success of subsequent matches. The
advantage of writing my own algorithm was that I could add specialised
markers to represent higher-level concepts that were more relevant to the
application
Tony Proctor
"Lorin" <Lorin@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:370A999E-BAE5-4DD6-B5F0-76FA0998702F@xxxxxxxxxxxxxxxx
VB6
Looking for help developing a string Search Ambiguous routine.
Something like the Find 'Use Pattern Matching' in the VB6 IDE would be
OK.
What I am planning to try is
Use 'Like' to see if the Search String is there.
Then use a combination of Instr and Mid$ to do the work.
That gets complex based on the Like pattern matching operators.
I guess I could limit it to * and ?
Hoping there is an easier/faster way than that.
Is there an API that will do this on a string?
I really would like to have a Like function that would return the
location
of the first chartacter of the Like match not just that it found it or
not.
How do I do this?
.
- Follow-Ups:
- Re: Search Ambiguous
- From: Rick Rothstein \(MVP - VB\)
- Re: Search Ambiguous
- References:
- Re: Search Ambiguous
- From: Rick Rothstein \(MVP - VB\)
- Re: Search Ambiguous
- Prev by Date: Re: Search Ambiguous
- Next by Date: Re: Search Ambiguous
- Previous by thread: Re: Search Ambiguous
- Next by thread: Re: Search Ambiguous
- Index(es):
Relevant Pages
|