Compare length of two strings: Difference between revisions
Content added Content deleted
Line 333: | Line 333: | ||
12 "short string"</pre> |
12 "short string"</pre> |
||
=={{header|J}}== |
|||
<pre> |
|||
NB. solution |
|||
NB. `Haruno-umi Hinemosu-Notari Notarikana' |
|||
NB. Spring ocean ; Swaying gently ; All day long. |
|||
,/ _2 }.\ ": (;~ #)&> <@(7&u:);._2 '春の海 ひねもすのたり のたりかな ' |
|||
│3│春の海 │ |
|||
│7│ひねもすのたり│ |
|||
│5│のたりかな │ |
|||
NB. # y is the tally of items (next-to-last dimension) in the noun y |
|||
# 323 43 5j3 |
|||
3 |
|||
# 'literal (a string)' |
|||
18 |
|||
/: 'cbad' NB. index ordering vector (grade up) |
|||
2 1 0 3 |
|||
;: 'j tokenize a sentence.' |
|||
┌─┬────────┬─┬─────────┐ |
|||
│j│tokenize│a│sentence.│ |
|||
└─┴────────┴─┴─────────┘ |
|||
#S:0 ;: 'j tokenize a sentence.' NB. length of leaves (lowest box level) |
|||
1 8 1 9 |
|||
A=: '1234567 abcd 123456789 abcdef' NB. global assignment |
|||
(\: #S:0) ;: A NB. order by grade down |
|||
┌─────────┬───────┬──────┬────┐ |
|||
│123456789│1234567│abcdef│abcd│ |
|||
└─────────┴───────┴──────┴────┘ |
|||
(;:'length literal') , ((;~ #)&> \: #S:0) ;: A NB. box incompatible types with header |
|||
┌──────┬─────────┐ |
|||
│length│literal │ |
|||
├──────┼─────────┤ |
|||
│9 │123456789│ |
|||
├──────┼─────────┤ |
|||
│7 │1234567 │ |
|||
├──────┼─────────┤ |
|||
│6 │abcdef │ |
|||
├──────┼─────────┤ |
|||
│4 │abcd │ |
|||
└──────┴─────────┘ |
|||
</pre> |
|||
=={{header|Java}}== |
=={{header|Java}}== |
||
{{Works with| Java | 11 }} |
{{Works with| Java | 11 }} |