Compare length of two strings: Difference between revisions
Content added Content deleted
imported>Chinhouse No edit summary |
|||
Line 1,939: | Line 1,939: | ||
abcdef |
abcdef |
||
abcd |
abcd |
||
</pre> |
|||
=={{header|MiniScript}}== |
|||
<syntaxhighlight lang="miniscript"> |
|||
// Simple version |
|||
print "Simple version:" |
|||
s2 = "This is the first string." |
|||
s1 = "This is string number two." |
|||
if s1.len > s2.len then |
|||
print s1.len + ": " + s1 |
|||
print s2.len + ": " + s2 |
|||
else |
|||
print s2.len + ": " + s2 |
|||
print s1.len + ": " + s1 |
|||
end if |
|||
// Extra credit. More than 2 strings |
|||
strings = ["qwerty", "abc", "#FFFFFFFF", "255,255,255,255", "3.14159"] |
|||
pairs = [] |
|||
for string in strings |
|||
pairs.push([string, string.len]) |
|||
end for |
|||
// sort by index descending |
|||
pairs.sort(1, false) |
|||
print |
|||
print "Extra credit:" |
|||
for pair in pairs |
|||
print pair[1] + ": " + pair[0] |
|||
end for |
|||
</syntaxhighlight> |
|||
{{out}} |
|||
<pre>Simple version: |
|||
26: This is string number two. |
|||
25: This is the first string. |
|||
Extra credit: |
|||
15: 255,255,255,255 |
|||
9: #FFFFFFFF |
|||
7: 3.14159 |
|||
6: qwerty |
|||
3: abc |
|||
</pre> |
</pre> |
||