Compare length of two strings: Difference between revisions
Content added Content deleted
(→OCaml: add) |
|||
Line 1,447: | Line 1,447: | ||
<pre>“marché”, byte length = 7, code points: 6 |
<pre>“marché”, byte length = 7, code points: 6 |
||
“marche”, byte length = 6, code points: 6</pre> |
“marche”, byte length = 6, code points: 6</pre> |
||
=={{header|OCaml}}== |
|||
<syntaxhighlight lang="ocaml">let () = |
|||
["abcd"; "123456789"; "abcdef"; "1234567"] |
|||
|> List.rev_map (fun s -> String.length s, s) |
|||
|> List.sort (Fun.flip compare) |
|||
|> List.iter (fun (l, s) -> Printf.printf "%u %s\n" l s)</syntaxhighlight> |
|||
{{out}} |
|||
<pre> |
|||
9 123456789 |
|||
7 1234567 |
|||
6 abcdef |
|||
4 abcd |
|||
</pre> |
|||
=={{header|Pascal}}== |
=={{header|Pascal}}== |