Anonymous user
Compare length of two strings: Difference between revisions
Added compare length of two strings for CFEngine
Walterpachl (talk | contribs) m (add REXX) |
(Added compare length of two strings for CFEngine) |
||
Line 378:
"abcdef" has length 6 and is neither the longest nor the shortest string
"abcd" has length 4 and is the shortest string
</pre>
=={{header|CFEngine}}==
<lang cfengine3>
bundle agent __main__
{
vars:
"strings" slist => { "abcd", "123456789", "abcdef", "1234567" };
"sorted[$(with)]"
string => "$(strings)",
with => string_length( "$(strings)" );
"sort_idx" slist => reverse( sort( getindices( "sorted" ), lex ) );
reports:
"'$(sorted[$(sort_idx)])' is $(sort_idx) characters in length.";
}
</lang>
{{output}}
<pre>
R: '123456789' is 9 characters in length.
R: '1234567' is 7 characters in length.
R: 'abcdef' is 6 characters in length.
R: 'abcd' is 4 characters in length.
</pre>
|