Compare length of two strings: Difference between revisions

no edit summary
No edit summary
Line 9:
Measure the length of your string in terms of bytes or characters, as appropriate for your language. If your language doesn't have an operator for measuring the length of a string, note it.
 
;Extra credit:
Let given more than two strings:
list = ["abcd","123456789","abcdef","1234567"]
Show the string in descending lenght order.
{{Template:Strings}}
<br><br>
Line 181 ⟶ 185:
 
=={{header|Ring}}==
===Two strings===
<lang ring>
see "working..." + nl
Line 202 ⟶ 207:
Compare length of two strings:
123456789 len = 9
abcd len = 4
done...
</pre>
===More than two strings===
<lang ring>
see "working..." + nl
 
lenList = []
list = ["abcd","123456789","abcdef","1234567"]
for n = 1 to len(list)
len = len(list[n])
add(lenList,[len,n])
next
 
lenList = sort(lenList,1)
lenList = reverse(lenList)
 
see "Compare length of strings in descending order:" + nl
for n = 1 to len(lenList)
see "" + list[lenList[n][2]] + " len = " + lenList[n][1] + nl
next
see "done..." + nl
</lang>
{{out}}
<pre>
working...
Compare length of strings in descending order:
123456789 len = 9
1234567 len = 7
abcdef len = 6
abcd len = 4
done...
2,468

edits