Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Matching on verriable length data.
Message
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00381819
Message ID:
00382072
Views:
22
>I have a phone # that is up to 16 digits long but always more than 7. I have a list of countries and each country has a code that is from 4 to 7 digits long and will match the first 4 - 7 digits of the phone#. The obvious (brute force) way to get the country from the phone# is to seek on the first 7 digits of the phone# and if it is not found seek for the first 6 digits and so on until a match is found. I don't like this method can anyone think of a better way?

One mechanism that noone suggested was to use the LIKE() function - store the masks for all prefixes with as many specific digits as it contains, and pad the right end with as many "?" as needed to get 7 characters. Your search now becomes:
*  Strip possible extraneous characters and get the lookup
cThingToFind = LEFT(CHRTRAN(thisform.txtPhoneNumber.value,"() -/+,",""),7)
SELECT LocPrefix
SET ORDER TO MyPrefix
SEEK LEFT(cThingToFind,4)
LOCATE REST FOR LIKE(MyPrefix,cThingToFind) WHILE LEFT(cThingToFind,4) = LEFT(MyPrefix,4)
*  ? Sorts after a digit, so it'll check 7 digit matches before 6 + ?, etc.
IOW, the table LocPrefix is laid out

MyPrefix C(7), MyCity C(20), MyState C(4), MyCountry C(20) ...

and has entries for the MyPrefix field of

1212???
3879877
20334??

and has an index on LEFT(MyPrefix,4) which does not have wildcards to position using SEEK. In theory at least, you can mix digits and wildcards anywhere after position 4 and use the SEEK positioning speedup
EMail: EdR@edrauh.com
"See, the sun is going down..."
"No, the horizon is moving up!"
- Firesign Theater


NT and Win2K FAQ .. cWashington WSH/ADSI/WMI site
MS WSH site ........... WSH FAQ Site
Wrox Press .............. Win32 Scripting Journal
eSolutions Services, LLC

The Surgeon General has determined that prolonged exposure to the Windows Script Host may be addictive to laboratory mice and codemonkeys
Previous
Reply
Map
View

Click here to load this message in the networking platform