Separate the house number from the street name: Difference between revisions
Content added Content deleted
(Added Go) |
|||
Line 642: | Line 642: | ||
1 => 「6」 |
1 => 「6」 |
||
</pre> |
|||
=={{header|Phix}}== |
|||
{{trans|Go}} |
|||
<lang Phix>function isDigit(integer ch) |
|||
return ch>='0' and ch<='9' |
|||
end function |
|||
function separateHouseNumber(sequence address) |
|||
address = split(address,no_empty:=true) |
|||
string street, house |
|||
integer h = 0 |
|||
if length(address)>1 then |
|||
string last = address[$] |
|||
if isDigit(last[1]) then |
|||
h = 1 |
|||
string penult = address[$-1] |
|||
if length(address)>2 |
|||
and isDigit(penult[1]) |
|||
and match("194",penult)!=1 then |
|||
h = 2 |
|||
end if |
|||
elsif length(address)>2 then |
|||
h = 2 |
|||
end if |
|||
end if |
|||
if h then |
|||
street = join(address[1..$-h]) |
|||
house = join(address[$-h+1..$]) |
|||
else |
|||
street = join(address) |
|||
house = "(none)" |
|||
end if |
|||
return {street,house} |
|||
end function |
|||
constant addresses = {"Plataanstraat 5", |
|||
"Straat 12", |
|||
"Straat 12 II", |
|||
"Dr. J. Straat 12", |
|||
"Dr. J. Straat 12 a", |
|||
"Dr. J. Straat 12-14", |
|||
"Laan 1940 - 1945 37", |
|||
"Plein 1940 2", |
|||
"1213-laan 11", |
|||
"16 april 1944 Pad 1", |
|||
"1e Kruisweg 36", |
|||
"Laan 1940-'45 66", |
|||
"Laan '40-'45", |
|||
"Langeloërduinen 3 46", |
|||
"Marienwaerdt 2e Dreef 2", |
|||
"Provincialeweg N205 1", |
|||
"Rivium 2e Straat 59.", |
|||
"Nieuwe gracht 20rd", |
|||
"Nieuwe gracht 20rd 2", |
|||
"Nieuwe gracht 20zw /2", |
|||
"Nieuwe gracht 20zw/3", |
|||
"Nieuwe gracht 20 zw/4", |
|||
"Bahnhofstr. 4", |
|||
"Wertstr. 10", |
|||
"Lindenhof 1", |
|||
"Nordesch 20", |
|||
"Weilstr. 6", |
|||
"Harthauer Weg 2", |
|||
"Mainaustr. 49", |
|||
"August-Horch-Str. 3", |
|||
"Marktplatz 31", |
|||
"Schmidener Weg 3", |
|||
"Karl-Weysser-Str. 6"} |
|||
procedure main() |
|||
printf(1,"Street House Number\n") |
|||
printf(1,"--------------------- ------------\n") |
|||
for i=1 to length(addresses) do |
|||
printf(1,"%-22s %s\n", separateHouseNumber(addresses[i])) |
|||
end for |
|||
end procedure |
|||
main()</lang> |
|||
{{out}} |
|||
<pre> |
|||
Street House Number |
|||
--------------------- ------------ |
|||
Plataanstraat 5 |
|||
Straat 12 |
|||
Straat 12 II |
|||
Dr. J. Straat 12 |
|||
Dr. J. Straat 12 a |
|||
Dr. J. Straat 12-14 |
|||
Laan 1940 - 1945 37 |
|||
Plein 1940 2 |
|||
1213-laan 11 |
|||
16 april 1944 Pad 1 |
|||
1e Kruisweg 36 |
|||
Laan 1940-'45 66 |
|||
Laan '40-'45 (none) |
|||
LangeloÙrduinen 3 46 |
|||
Marienwaerdt 2e Dreef 2 |
|||
Provincialeweg N205 1 |
|||
Rivium 2e Straat 59. |
|||
Nieuwe gracht 20rd |
|||
Nieuwe gracht 20rd 2 |
|||
Nieuwe gracht 20zw /2 |
|||
Nieuwe gracht 20zw/3 |
|||
Nieuwe gracht 20 zw/4 |
|||
Bahnhofstr. 4 |
|||
Wertstr. 10 |
|||
Lindenhof 1 |
|||
Nordesch 20 |
|||
Weilstr. 6 |
|||
Harthauer Weg 2 |
|||
Mainaustr. 49 |
|||
August-Horch-Str. 3 |
|||
Marktplatz 31 |
|||
Schmidener Weg 3 |
|||
Karl-Weysser-Str. 6 |
|||
</pre> |
</pre> |
||