Hello Community,
i have to copy an adress which could be like: "tumleby 12 5340 taastrup"
i would then like to copy this into three parts so that it would be:
string1 = tumleby
string2 = 12
string3 = 5340
string4 = taastrup
however, i can't really figure out how you could do this since the adress can change so that the different strings could be bigger or smaller
does anyone have any idea to how this could be done?
#RumbaHei Besafe,
first off, I think the beast course of action here would be not to forget the Pareto principle (https://en.wikipedia.org/wiki/Pareto_principle). I would aim to handle most scenarios and not all. So you first need to make some assumptions
e.g.
1. All addresses are Danish, so we will always have a four digit Postcode
2. delimited will either be a "," or a " ".
Then anything which falls outside of these assumptions gets recorded into a "bad" file for manual intervention.
My next step would be to split the address string into its various pieces, House address, Postcode and Area.
e.g.
Split "tumleby 12 5340 taastrup" in to "Tumleby", "12", "5340" and "Taastrup"
You can use Instr() in a For loop to first find any ",". If I find a comma, I would then split the string and check for any spaces after the comma in the remainder of the string and remove those and the comma, e.g. "tumleby 12, 5340 taastrup" would become "tumleby 12" and "5340 taastrup"
Next I would use InStr to check for any remaining spaces and split the strings if I find any, so "tumleby 12" and "5340 taastrup" become, "tumleby", "12", "5340" and "taastrup".
So now I have all of the address broken into it's sub strings. Next I check each from the last to the first to see if it's a four digit number i.e. using Len() and cInt().
When I find my Post code, then I can start to rebuild the address. Any string before the Post code are the House address, then I have the Postcode, and anything after the Postcode is the Area
Before I provide a sample of the above logic, it would be good to get clarification in terms of the rules (assumptions) which apply. e.g., maybe we need to check for a "-" between the Postcode and Area, etc.
MVH
Tom