#57718 - 10/14/20 03:14 PM
extract CIty Province and ZIP code from address
|
OL Expert
Registered: 01/29/14
Posts: 400
Loc: Home
|
Hi, can someone help me to extract City, Province and Postal Code from the last line of multiple line address, from line 1-6 For example:
FirstName Last Name 999 Sample Street Post Box 999999 City Province AxA 9X9
or
FirstName Last Name 999 Sample Street City Province AxA 9X9
I think it needs to start reading from last line 6 of address until it's not blank, and then extracting each word after each space and save them into a local veritable. I guess I said it but I don't know how to do it in PressTalk! your help is appreciated.
THANKS
_________________________
Peace
|
Top
|
|
|
|
#57722 - 10/15/20 03:44 AM
Re: extract CIty Province and ZIP code from address
[Re: Sami786]
|
OL User
Registered: 06/12/09
Posts: 58
Loc: Japan
|
That like follow talk may help. 1. search 'City' word in 6-1 line for search city item and split each word by blank 2. show addr(city, Province etc) each fields in array as scenario.
you can set that value to use as other variable.
-- define(&x,integer,1) define(&y,integer,0) define(&z,string,'') define( &addr,arraystring,['','','','',''] )
for(&x,6,-1,1) &z := trim(@(&x,1,60)) if(pos('City', &z) > 0) search(&z,' ') &addr[&y]:= &z &y :=&y +1 endsearch() &addr[&y]:= &z exit() endif()
endfor() show(&addr[0]) crlf() show(&addr[1]) crlf() show(&addr[2]) crlf() show(&addr[3]) --
|
Top
|
|
|
|
#57724 - 10/15/20 08:42 AM
Re: extract CIty Province and ZIP code from address
[Re: Sami786]
|
OL Expert
Registered: 10/03/16
Posts: 681
Loc: Québec, Canada
|
The problem with your data is knowing how to separate city from province. Ex: Vancouver British Columbia T6B 2R3 Montreal Quebec H1V 2C8 You and I know that the city is Vancouver and the province is British Columbia. The code doesn't. It will look at spaces between word. So starting from the end of the line is a good idea. Since we know that the postal code is in the format of XXX XXX, we can extract it and continue to the next word (preceding word(s)). I would suggest an array that would hold a list of all provinces. This way, when you extract the part of the string once you have reach a space, you can compare to the list. If it isn't there, then you keep on extracting words until the following space. Once you have found your province, the rest is a city. Something like the following should do it:
define(&provinces,arraystring,['Alberta','British Columbia','Manitoba','New Brunswick','Newfoundland and Labrador','Nova Scotia','Ontario','Prince Edward Island','Quebec','Saskatchewan','Northwest Territories','Nunavut','Yukon'])
define(&lineNumber,integer,0)
define(&theLine,string,'')
define(&tempStr,string,'')
define(&city,string,'')
define(&province,string,'')
define(&zip,string,'')
%Get your city province zip line
for(&lineNumber,6,-1,1)
if(trim(@(&lineNumber,1,100)) <> '')
exit()
endif
endfor()
&theLine := trim(@(&lineNumber,1,100))
&zip := right(&theLine,7)
&theLine := trim(left(&theLine,length(&theLine)-7))
define(&index,integer,0)
repeat
&tempStr := right(&theLine,1) + &tempStr
&theLine := left(&theLine,length(&theLine)-1)
for(&index,0,1,12)
if(&tempStr = &provinces[&index])
&province := &tempStr
&city := &theLine
exit()
endif
endfor()
until(&theLine = '')
show('City = '+&city)
crlf(0.16)
show('Province = '+&province)
crlf(0.16)
show('Zip = '+&zip)
_________________________
♪♫♪♫ 99 frigging bugs in my code 99 frigging bugs Take one down Code around 127 frigging bugs in my code ♪♫♪♫
|
Top
|
|
|
|
#57725 - 10/15/20 01:52 PM
Re: extract CIty Province and ZIP code from address
[Re: Sami786]
|
OL Expert
Registered: 01/29/14
Posts: 400
Loc: Home
|
Thank you Hirot, my best shot was to read from last line Thank you Jean, your code works very good for City, Province and PCode, but I'm facing another problem! I also need to print address line 2 and 3 (if any) to the address box on the form. FirstName LastName -->999 Sample Street -->Post Box 999999 City Province AxA 9X9 So I know first line of address is always name and last line is always City, Province and PCode. Now how do I know if line 3 (Post Box 999999) is also for address 1? THANKS
Edited by Sami786 (10/15/20 01:54 PM)
_________________________
Peace
|
Top
|
|
|
|
#57726 - 10/15/20 01:54 PM
Re: extract CIty Province and ZIP code from address
[Re: Sami786]
|
OL Expert
Registered: 10/03/16
Posts: 681
Loc: Québec, Canada
|
Well, once you have remove line 1 and last line, the rest is most likely for the address...no?
_________________________
♪♫♪♫ 99 frigging bugs in my code 99 frigging bugs Take one down Code around 127 frigging bugs in my code ♪♫♪♫
|
Top
|
|
|
|
#57727 - 10/15/20 01:56 PM
Re: extract CIty Province and ZIP code from address
[Re: Sami786]
|
OL Expert
Registered: 01/29/14
Posts: 400
Loc: Home
|
That's correct, let me try if I can do this, thanks again!
_________________________
Peace
|
Top
|
|
|
|
#57729 - 10/19/20 10:53 AM
Re: extract CIty Province and ZIP code from address
[Re: Sami786]
|
OL Expert
Registered: 01/29/14
Posts: 400
Loc: Home
|
an if statement worked, thanks again!
_________________________
Peace
|
Top
|
|
|
|
|
|