Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.
Originally posted by: zon
Hi,
I'm trying to find the longest exact match between a destination number and a group of country codes. For example:
DESTINATION NUMBER = 005518352XXXXX
Country Code 0055 is Brazil. But in my country codes group, i've not only 0055, but also all other country codes inside 0055 to distinguise from fixed or mobile destinations (for instance, 005511 (fixed destin), 0055007 (mobile destin) and so on).
So I want to match to the longest country code in this group. In this case, the longest would be 005518.
The code i wrote first was this:
------------------------------
if not inRec:
return False
dest = inRec['DESTINATION']
found = False
i=0
while not found and i<len(self.destHash):
prefix = self.destHash[i]
if dest.startswith(prefix):
found = True
rec = self.lookupList[i]
i = i+1
outRec = self.outputs[0].newRecord()
outRec._copyFrom(inRec)
if found:
outRec["NIVEL_1"] = rec["NIVEL_1"]
outRec["NIVEL_2"] = rec["NIVEL_2"]
outRec["NIVEL_3"] = rec["NIVEL_3"]
outRec["COSTBAND_ID_RES"] = rec["COSTBAND_ID_RES"]
outRec["COSTCODE"] = rec["COSTCODE"]
outRec["COSTCODE_NAME"] = rec["COSTCODE_NAME"]
outRec["PI-O"] = rec["PI-O"]
self.outputs[0].write(outRec)
return True
----------------------------------
But this way, is not returning the longest. Am I doing something wrong? Can someone help me with this subject?
Best Regards,
Natanael Moreira