Compare length of two strings: Difference between revisions
Content added Content deleted
RandomTask (talk | contribs) |
(added Emacs Lisp code to order strings by length) |
||
Line 1,265: | Line 1,265: | ||
scmp "Rosetta" "Code" |
scmp "Rosetta" "Code" |
||
</syntaxhighlight> |
</syntaxhighlight> |
||
=={{header|Emacs Lisp}}== |
|||
<syntaxhighlight lang="lisp"> |
|||
(defun sort-list-by-string-length (list-of-strings) |
|||
"Take list of strings and order from longest to shortest." |
|||
(sort list-of-strings 'longer-string)) ; uses "longer-string" function below for sort order |
|||
(defun longer-string (string-1 string-2) |
|||
"Test if STRING-1 is longer than STRING-2." |
|||
(> (length string-1) (length string-2))) ; is STRING-1 longer than STRING-2? |
|||
</syntaxhighlight> |
|||
{{out}} |
|||
(sort-list-by-string-length '("abcd" "123456789" "abcdef" "1234567")) |
|||
<pre> |
|||
("123456789" "1234567" "abcdef" "abcd") |
|||
</pre> |
|||
=={{header|EMal}}== |
=={{header|EMal}}== |