|
|
|
|
|
by patrickas
1905 days ago
|
|
Raku seems to be more correct (DWIM) in this regard than all the examples given in the post... my \emoji = "\c[FACE PALM]\c[EMOJI MODIFIER FITZPATRICK TYPE-3]\c[ZERO WIDTH JOINER]\c[MALE SIGN]\c[VARIATION SELECTOR-16]";
#one character
say emoji.chars; # 1
#Five code points
say emoji.codes; # 5
#If I want to know how many bytes that takes up in various encodings...
say emoji.encode('UTF8').bytes; # 17 bytes
say emoji.encode('UTF16').bytes; # 14 bytes
Edit: Updated to use the names of each code point since HN cannot display the emoji |
|
No such method 'length' for invocant of type 'Str'. Did you mean any of these: 'codes', 'chars'?
Because as the article points out, the "length" of a string is an ambiguous concept these days.