String length: Difference between revisions
→groovy Character Length: add recommended examples
(→{{header|Wren}}: Added Grapheme Length) |
(→groovy Character Length: add recommended examples) |
||
Line 1,608:
Calculating "Byte-length" (by which one typically means "in-memory storage size in bytes") is not possible through the facilities of the Groovy language alone. Calculating "Character length" is built into the Groovy extensions to java.lang.String.
===Character Length===
<syntaxhighlight lang="groovy"
println "Hello World!".size()
println "møøse".size()
println "𝔘𝔫𝔦𝔠𝔬𝔡𝔢".size()
println "J̲o̲s̲é̲".size()
</syntaxhighlight>
Output:
<
12
5
14
8
</pre>
Note: The Java "String.length()" method also works in Groovy, but "size()" is consistent with usage in other sequential or composite types.
|