Compare length of two strings: Difference between revisions

Added AutoHotkey
(added AWK)
(Added AutoHotkey)
Line 36:
"short" has length: 5 bytes.
</pre>
 
=={{header|AutoHotkey}}==
<lang AutoHotkey>list := ["abcd","123456789","abcdef","1234567"]
 
sorted := []
for i, s in list
sorted[0-StrLen(s), s] := s
for l, obj in sorted
{
i := A_Index
for s, v in obj
{
if (i = 1)
result .= """" s """ has length " 0-l " and is the longest string.`n"
else if (i < sorted.Count())
result .= """"s """ has length " 0-l " and is neither the longest nor the shortest string.`n"
else
result .= """"s """ has length " 0-l " and is the shorted string.`n"
}
}
MsgBox % result</lang>
{{out}}
<pre>"123456789" has length 9 and is the longest string.
"1234567" has length 7 and is neither the longest nor the shortest string.
"abcdef" has length 6 and is neither the longest nor the shortest string.
"abcd" has length 4 and is the shorted string.</pre>
 
=={{header|AWK}}==
<lang AWK>
299

edits