Documentation for routine
chars assembled from the following types:
multi sub chars(Cool $x) multi sub chars(Str:D $x) multi sub chars(str $x --> int) method chars(--> Int:D)
Coerces the invocant (or in sub form, its argument) to Str, and returns the number of characters in the string. Please note that on the JVM, you currently get codepoints instead of graphemes.
say 'møp'.chars; # OUTPUT: «3␤» say 'ã̷̠̬̊'.chars; # OUTPUT: «1␤» say '👨👩👧👦🏿'.chars; # OUTPUT: «1␤»
If the string is native, the number of chars will be also returned as a native
Graphemes are user visible characters. That is, this is what the user thinks of as a “character”.
Graphemes can contain more than one codepoint. Typically the number of graphemes and codepoints differs when
Extend characters are involved (also known as Combining characters), but there are many other cases when this may happen. Another example is
\c[ZWJ] (Zero-width joiner).
You can check
Grapheme_Cluster_Break property of a character in order to see how it is going to behave:
say ‘ã̷̠̬̊’.uniprops(‘Grapheme_Cluster_Break’); # OUTPUT: «(Other Extend Extend Extend Extend)␤» say ‘👨👩👧👦🏿’.uniprops(‘Grapheme_Cluster_Break’); # OUTPUT: «(E_Base_GAZ ZWJ E_Base_GAZ ZWJ E_Base_GAZ ZWJ E_Base_GAZ E_Modifier)␤»
multi sub chars(Cool $x --> Int:D) multi sub chars(Str:D $x --> Int:D) multi sub chars(str $x --> int) multi method chars(Str:D: --> Int:D)
Returns the number of characters in the string in graphemes. On the JVM, this currently erroneously returns the number of codepoints instead.
Returns the numbers of characters in the matched string.
Returns the same as
chars as payload.