Compare length of two strings
So... In what way does this task differ significantly from String length? Other than being horribly under specified?
In the modern world, string "length" is pretty much a useless measurement, especially in the absence of a specified encoding; hence Raku not even having an operator: "length" for strings.
say 'Strings (π¨βπ©βπ§βπ¦, π€πΊπΈ, BOGUS!) sorted: "longest" first:';
say "$_: characters:{.chars}, Unicode code points:{.codes}, UTF-8 bytes:{.encode('UTF8').bytes}, UTF-16 bytes:{.encode('UTF16').bytes}" for <π¨βπ©βπ§βπ¦ BOGUS! π€πΊπΈ>.sort: -*.chars;
Output:
Strings (π¨βπ©βπ§βπ¦, π€πΊπΈ, BOGUS!) sorted: "longest" first:
BOGUS!: characters:6, Unicode code points:6, UTF-8 bytes:6, UTF-16 bytes:12
π€πΊπΈ: characters:2, Unicode code points:3, UTF-8 bytes:12, UTF-16 bytes:12
π¨βπ©βπ§βπ¦: characters:1, Unicode code points:7, UTF-8 bytes:25, UTF-16 bytes:22
Last updated
Was this helpful?