Compare length of two strings: Difference between revisions
Content added Content deleted
(Add Factor) |
(Added Forth entry) |
||
Line 684: | Line 684: | ||
{ "123456789" "1234567" "abcdef" "abcd" } |
{ "123456789" "1234567" "abcdef" "abcd" } |
||
</pre> |
</pre> |
||
=={{header|Forth}}== |
|||
{{works with|gforth|0.7.3}} |
|||
Traditionaly, Forth strings are 'counted strings' (to oppose to nul terminated strings from C). So, no need to search the length, we just need to swap strings if necessary before printing. |
|||
<syntaxhighlight lang="Forth"> |
|||
: say dup . ." : " type ; |
|||
: comp-strings |
|||
2 pick over |
|||
> if 2swap then |
|||
cr say cr say cr |
|||
; |
|||
</syntaxhighlight> |
|||
{{out}}<pre>s" shortest string" s" longest string" comp-strings |
|||
15 : shortest string |
|||
14 : longest string |
|||
ok |
|||
s" longest string" s" shortest string" comp-strings |
|||
15 : shortest string |
|||
14 : longest string |
|||
ok |
|||
</pre> |
|||
=={{header|Fortran}}== |
=={{header|Fortran}}== |