Compare length of two strings: Difference between revisions

no edit summary
No edit summary
Line 2,795:
</pre>
 
=={{header|TransdSwift}}==
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.
MainModule: {
<syntaxhighlight lang="SchemeSwift">#lang transd
let list v:= ["abcd", "abcd🤦‍♂️", "123456789", "abcdef", "1234567"],
 
list.sorted { $0.count > $1.count }.forEach { string in
_start: (λ
print(for s in "\(sortstring) vhas \(λ l String(string.count) r String(characters")
}
(ret (< (size r) (size l))))) do
}</syntaxhighlight>
(lout width: 10 s " : " (size s) " code points") )
)
}</syntaxhighlight>
{{out}}
<pre>
123456789 :has 9 code pointscharacters
1234567 :has 7 code pointscharacters
abcdef :has 6 code pointscharacters
abcd🤦‍♂️ has 5 characters
abcd : 4 code points
abcd has 4 characters
</pre>
 
1

edit