5 ms·
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
by patrickas 6y 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
- duskwuff 6y agoYou can represent it as a sequence of escapes. If Raku handles this the same way as Perl5, it should be: $a = "\N{FACE PALM}\N{EMOJI MODIFIER FITZPATRICK TYPE-3}\N{ZERO WIDTH JOINER}\N{MALE SIGN}\N{VARIATION SELECTOR-16}";
- csharptwdec19 6y agonow do it in YAML
- cjm42 6y agoAnd if you try to say emoji.length, you'll get an error: 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.