Jump to content

Compare length of two strings: Difference between revisions

→‎{{header|Lua}}: added Lua solution
No edit summary
(→‎{{header|Lua}}: added Lua solution)
Line 1,080:
"longer" has length (codepoints) 6 and utf8 byte length 6.
</pre>
 
=={{header|Lua}}==
<lang lua>function test(list)
table.sort(list, function(a,b) return #a > #b end)
for _,s in ipairs(list) do print(#s, s) end
end
test{"abcd", "123456789", "abcdef", "1234567"}</lang>
{{out}}
<pre>9 123456789
7 1234567
6 abcdef
4 abcd</pre>
 
=={{header|Mathematica}} / {{header|Wolfram Language}}==
<lang Mathematica>list = {"abcd", "123456789", "abcdef", "1234567"};
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.