>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:
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)
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