?
Solved

Can't use wildcards in INSTR

Posted on 2002-07-28
7
Medium Priority
?
2,311 Views
Last Modified: 2010-05-18
I need to search text files for phone numbers.  Basically I want to look for (###)###-####, recognize that as a phone number and pick it out of the text file.  I try this in INSTR but it doesn't seem to be accepting wildcards (or I'm using them incorrectly).  The LIKE operator works but only returns true or false, it doesn't tell me where in the text file it found the match.  Any ideas?
0
Comment
Question by:michaelwarden
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 53

Expert Comment

by:Ryan Chong
ID: 7184521
Actually INSTR function will perform as wildcard LIKE:

Example:

strPhoneNum = "(607)1156-8896"

strSearch = "15"

iPos = Instr(1,strPhoneNum, strSearch)

iPos will return a number greater than 0 (that's the first position of search string) if the search string find in the whole string.
0
 
LVL 4

Expert Comment

by:mcoop
ID: 7184539
I think what he's looking for is a substring like...
  "(203)*-1234"

This can be achieved by bracketing the required strings...
  first find "(203), then test for "-1234" in the remainder of the primary string.

If the substring was "(203)???-1234" (i.e a fixed number of chars), then rather than testing the 'rest' of the string, test for an exact match at the known position of "(203)" -plus 5 (for (203)) and  plus 3 (for the three wildcard) characters.

This could be formed into a funciton fairly easily.
0
 
LVL 4

Accepted Solution

by:
mcoop earned 300 total points
ID: 7184578
Oh - and to refer to the actual example  (###)###-####

I would probably look in a slightly different way....

Searh for the ( and ) first (least likely to occur), then the block of 4 numerics, then walk backwards to check the area code and exchange prefix digits

Of course you also should consider the fact that some people don't put the punctuation where it should be (capitalisation, hyphens and spaces etc)  so perhaps it is worth pre-processing and index that file against the source file  to remove all ambiguities, only then scan for the formatted number strings, and only then refer back to the original file to extract the entry as actually keyed in... (if that's really necessary)

0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 4

Expert Comment

by:TigerZhao
ID: 7184812
Use Microsoft VBScript Regular Expressions

Sub FindPhoneNumber(ByVal inputString)
    Dim regex, match, matches
    Set regex = New RegExp
    regex.Pattern = "\(\d{3}\)\d{3}-\d{4}"
    regex.Global = True
    Set matches = regex.Execute(inputString)
    For Each match In matches
        Debug.Print match.Value
    Next
End Sub
0
 
LVL 4

Expert Comment

by:mcoop
ID: 7185141

Where are the references for the RegExp object ?
I've seen them before, but can't remember who/where I saw it used...  I also believe that there may be some limitations of RegExp that will thwart michaelwarden's application...
0
 

Author Comment

by:michaelwarden
ID: 7186217
i was hoping there was an easier way, but mcoop pointed me in the right direction and i have it working now, thanks a lot for all the posts.
0
 
LVL 4

Expert Comment

by:mcoop
ID: 7186575
Thanks...
0

Featured Post

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question