Compare length of two strings: Difference between revisions
no edit summary
No edit summary |
|||
Line 2,795:
</pre>
Swift provides a simple ''count'' property to find how many syntactic characters are in any given String. When counting bytes Swift supports Unicode codepoints.
In this example we use the ''sorted'' and ''forEach'' methods from the Sequence protocol to first sort our list into a new Array and then print each item in order. String interpolation is used to print the details of each item.
▲=={{header|Transd}}==
<syntaxhighlight lang="Scheme">#lang transd▼
Here we use anonymous argument names with the ''sorted'' closure and a named argument with the ''forEach'' to illustrate how to use either style.
let list
list.sorted { $0.count > $1.count }.forEach { string in
}
▲}</syntaxhighlight>
{{out}}
<pre>
abcd🤦♂️ has 5 characters
abcd has 4 characters
</pre>
|