Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Can't use wildcards in INSTR

Posted on 2002-07-28
7
Medium Priority
?
2,393 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

598 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