KDrago
asked on
Search address string and parse out zip code
Hello -
I am looking to search a string for a zip code. We have a field in a Notes db that has city, state and zip code combined into one text field. Through lotusscript I need to isolate the 5 digit zip from the rest of the text. Since it is a free text field data has been entered inconsistently, so there is no specific delimiter I can look for. How can I search for 5 consecutive numbers?
Thanks in advance.
I am looking to search a string for a zip code. We have a field in a Notes db that has city, state and zip code combined into one text field. Through lotusscript I need to isolate the 5 digit zip from the rest of the text. Since it is a free text field data has been entered inconsistently, so there is no specific delimiter I can look for. How can I search for 5 consecutive numbers?
Thanks in advance.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Hey CRAK, working overtime eh? :-))
No.... probably the same reasons as you: Nothing on TV / in for a challenge.
Tried a crash course Italian earlier on. I was able to read the middle part pretty well.... quite similar to BASIC really! ;-))
Tried a crash course Italian earlier on. I was able to read the middle part pretty well.... quite similar to BASIC really! ;-))
ASKER
Thanks to both of you for your help. Either of these solutions will work well. I went with Sjef's only because it involved less code.
CRAK,
I've tried to do things somewhat similar to you, but inverse. You're actually doing a lot of processing to avoid brute force. On a short field (and addresses tend to be short fields!), brute force is actually more efficient.
However, something like this CAN be more efficient. Instead of dropping the numbers out, you drop everything else out, replacing it with spaces, triming extra spaces, and taking the last remaining string. I think I implemented that once, but can't find the code.
I've tried to do things somewhat similar to you, but inverse. You're actually doing a lot of processing to avoid brute force. On a short field (and addresses tend to be short fields!), brute force is actually more efficient.
However, something like this CAN be more efficient. Instead of dropping the numbers out, you drop everything else out, replacing it with spaces, triming extra spaces, and taking the last remaining string. I think I implemented that once, but can't find the code.
Heh, thought of that too, even in Formula it should be doable, but in LotusScript the complexity of the algorithm cannot really be justified. My other idea was to use a Regular Expression (there's a Windows DLL), but in this case that's really overkill. I assumed the Like-operator and the single loop would be the most effective way. Last one, and a totally absurd suggestion: generate an LR(1) parser using Yacc...
Thanks for the grade!!
Thanks for the grade!!
Most brute-force approaches I've seen continuously shorten source strings: they check the first 'n' characters, drop the 1st char and retry.
Approaches like mine may easily beat that, provided that the source string is large enough and there aren't too many occurrances of the searchstrings.
Sjef's code doesn't affect the source string at all! It doesn't waste time copying chunks of string up and down through RAM. No doubt it's faster.
Just please don't spoil my creative mood....
;-)
Approaches like mine may easily beat that, provided that the source string is large enough and there aren't too many occurrances of the searchstrings.
Sjef's code doesn't affect the source string at all! It doesn't waste time copying chunks of string up and down through RAM. No doubt it's faster.
Just please don't spoil my creative mood....
;-)
It works well though!
It's designed for a button on a form (UIDoc in editmode). I'm sure you'll be able to rewrite that to a NotesDocument-base.
Open in new window