Compare length of two strings: Difference between revisions

Content added Content deleted
(Added XPL0 example.)
Line 785: Line 785:
Sorting in descending order by length in codepoints:
Sorting in descending order by length in codepoints:
[abcd, 123456789, abcdef, 1234567] -> [123456789, 1234567, abcdef, abcd]
[abcd, 123456789, abcdef, 1234567] -> [123456789, 1234567, abcdef, abcd]
</pre>

=={{header|XPL0}}==
<lang XPL0>string 0; \use zero-terminated string convention

func StrLen(A); \Return number of characters in an ASCIIZ string
char A;
int I;
for I:= 0 to -1>>1 do
if A(I) = 0 then return I;

char List;
int M, N, SN, Len, Max;
[List:= ["abcd","123456789","abcdef","1234567"];
for M:= 0 to 3 do
[Max:= 0;
for N:= 0 to 3 do
[Len:= StrLen(@List(N,0));
if Len > Max then [Max:= Len; SN:= N];
];
Text(0, @List(SN,0));
Text(0, " length is "); IntOut(0, StrLen(@List(SN,0))); CrLf(0);
List(SN, 0):= 0; \truncate largest string
];
]</lang>

{{out}}
<pre>
123456789 length is 9
1234567 length is 7
abcdef length is 6
abcd length is 4
</pre>
</pre>