Separate the house number from the street name: Difference between revisions
Separate the house number from the street name (view source)
Revision as of 13:46, 28 August 2022
, 1 year agosyntax highlighting fixup automation
m (→{{header|J}}: improve heuristics) |
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
||
Line 49:
{{trans|Nim}}
<
V fields = address.split_py()
V last = fields.last
Line 102:
L(address) Addresses
V (street, house) = separateHouseNumber(address)
print(street.rjust(22)‘ ’(I !house.empty {house} E ‘(none)’))</
{{out}}
Line 144:
=={{header|EchoLisp}}==
<
(lib 'struct)
(lib 'sql)
Line 208:
"Schmidener Weg 3"
"Karl-Weysser-Str. 6"))
</syntaxhighlight>
{{out}}
<pre>
Line 250:
=={{header|F_Sharp|F#}}==
<
// Seperate house number and street in Dutch addresses. Nigel Galloway: September 23rd., 2021
let fN g=let n=System.Text.RegularExpressions.Regex.Match(g,@"(\s\d+[-/]\d+)|(\s(?!1940|1945)\d+[a-zI. /]*\d*)$") in if n.Success then Some(g.[0..n.Index],n.Value) else None
Line 256:
printfn " Street Number\n ______ ______"
td|>List.iter(fun g->match fN g with Some(n,g)->printfn $"%27s{n.Trim()} %s{g}" |_->printfn $"FAILED %s{g}")
</syntaxhighlight>
{{out}}
<pre>
Line 299:
=={{header|Go}}==
{{trans|Kotlin}}
<
import (
Line 375:
fmt.Printf("%-22s %s\n", street, house)
}
}</
{{out}}
Line 421:
{{Works with|GHC|7.8.3}}
<
{- Recommended package versions to use:
Line 521:
Right r -> return r
pairs <- mapM (splitAddress rx) testSet
mapM_ T.putStrLn $ formatPairs pairs</
{{out}}
<pre>
Line 564:
'''Solution''':
<
digit=: '0123456789'
nope=: {{>./({.I.y=' '),1+I. special +./@:(E."1) y}}
here=: {{I.1,~y e.digit}}
din5008=: ({.;}.)~ here {.@#~ nope < here</
Sample data:
<
Straat 12
Straat 12 II
Line 606:
Schmidener Weg 3
Karl-Weysser-Str. 6
)</
'''Example''':<
┌───────────────────┬────────────────┐
│Straat │12 │
Line 673:
├───────────────────┼────────────────┤
│Karl-Weysser-Str. │6 │
└───────────────────┴────────────────┘</
=={{header|jq}}==
Line 685:
"(?<s>.*) (?<n> (\\s\\d+[-/]\\d+) | (\\s(?!1940|1945)\\d+[a-zI. /]*\\d*)$ | \\d+\\['][40|45]$ )"
</pre>
<
"^ (?<s>.*?) \\s+"
+ " (?<n>\\d* ( \\-|\\/)? \\d*"
Line 700:
| .n |= if . == "" or . == null then "(none)" else . end ;
def lpad($len): tostring | ($len - length) as $l | (" " * $l)[:$l] + .;</
'''The Task'''
<
"Plataanstraat 5",
"Straat 12",
Line 745:
| "\(.s|lpad(22)) \(.n)" ) ;
task</
{{out}}
<pre>
Line 787:
=={{header|Julia}}==
Uses the regex from the Perl version.
<
(
\d* (\-|\/)? \d*
Line 837:
end
end
</
<pre>
Plataanstraat 5 split as street => Plataanstraat, number => 5
Line 875:
=={{header|Kotlin}}==
<
val r = Regex("""\s+""")
Line 939:
println("${street.padEnd(22)} ${if (house != "") house else "(none)"}")
}
}</
{{out}}
Line 982:
=={{header|Nim}}==
{{trans|Go}}
<
from unicode import align
Line 1,037:
for address in Addresses:
let (street, house) = address.separateHouseNumber()
echo street.align(22), " ", if house.len != 0: house else: "(none)"</
{{out}}
Line 1,077:
=={{header|Perl}}==
<
'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',
Line 1,097:
$]x;
$number ? printf "%-26s\t%s\n", ($street, $number) : ($_, "\t(no match)");
}</
{{out}}
<pre style="height:35ex">Plataanstraat 5
Line 1,135:
=={{header|Phix}}==
{{trans|Go}}
<!--<
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #008080;">function</span> <span style="color: #000000;">isDigit</span><span style="color: #0000FF;">(</span><span style="color: #004080;">integer</span> <span style="color: #000000;">ch</span><span style="color: #0000FF;">)</span>
Line 1,211:
<span style="color: #008080;">end</span> <span style="color: #008080;">procedure</span>
<span style="color: #000000;">main</span><span style="color: #0000FF;">()</span>
<!--</
{{out}}
<pre>
Line 1,253:
=={{header|Python}}==
<!-- ?? missing code ?? -->
<
Plataanstraat 5 split as (Plataanstraat, 5)
Straat 12 split as (Straat, 12)
Line 1,286:
Marktplatz 31 split as (Marktplatz, 31)
Schmidener Weg 3 split as (Schmidener Weg, 3)
Karl-Weysser-Str. 6 split as (Karl-Weysser-Str., 6)''')</
=={{header|Racket}}==
Line 1,292:
Same as other regexp-splittings on this page. (I don't see much point in this, but the related [[Starting_a_web_browser]] seems like a good idea.)
<
#lang racket
Line 1,344:
(cond [(splits-adressen str) => cdr]
[else '???])))
</syntaxhighlight>
{{out}}
Line 1,393:
in places such as the U.S. where each block gets a hundred house numbers
to play with, and there are cities with hundreds of blocks along a street.)
<syntaxhighlight lang="raku"
( .*? )
Line 1,405:
$
] for lines;</
{{out}}
<pre>「Plataanstraat 5」
Line 1,541:
=={{header|REXX}}==
<
!= '│' /*a pipe-ish symbol for $ concatenation*/
$= "Plataanstraat 5" ! ,
Line 1,597:
(datatype(e, 'N') & pl & \verify("'", p, "M")) then s=s-1
if s==0 then s=n /*if no split, then relocate split to ∞*/
return s /* [↑] indicate where to split the txt*/</
{{out|output|text= when using the default (internal) input:}}
<pre>
Line 1,636:
=={{header|Scala}}==
<
val extractor = new scala.util.matching.Regex( """(\s\d+[-/]\d+)|(\s(?!1940|1945)\d+[a-zI. /]*\d*)$|\d+\['][40|45]$""")
Line 1,679:
adressen.foreach(s => println(f"$s%-25s split as ${splitsAdressen(s)}"))
}</
{{out}}
<pre>Plataanstraat 5 split as (Plataanstraat, 5)
Line 1,717:
=={{header|Sidef}}==
{{trans|Raku}}
<
( .*? )
(?:
Line 1,736:
warn "Can't parse: «#{line}»"
}
}</
{{out}}
<pre>
Line 1,776:
=={{header|Tcl}}==
{{trans|Scala}}
<
set RE {(?x)
^ (.*?) (
Line 1,829:
lassign [split_DE_NL_address $streetAddress] str num
puts "split <$streetAddress> as <$str> <$num>"
}</
{{out}}
<pre>
Line 1,868:
=={{header|TUSCRIPT}}==
<
$$ MODE DATA
Line 1,919:
TRACE *output
</syntaxhighlight>
Output:
<pre style='height:30ex;overflow:scroll'>
Line 1,963:
{{libheader|Wren-pattern}}
{{libheader|Wren-fmt}}
<
import "/fmt" for Fmt
Line 2,034:
if (house == "") house = "(none)"
Fmt.print("$-22s $s", street, house)
}</
{{out}}
|