UTF-8 encode and decode: Difference between revisions

→‎{{header|Perl 6}}: Add Perl 6 example
(Initial task description, Common Lisp solution)
 
(→‎{{header|Perl 6}}: Add Perl 6 example)
Line 157:
T
</lang>
 
=={{header|Perl 6}}==
{{works with|Rakudo|2017.02}}
Pretty much all built in to the language.
<lang perl6>say sprintf("%-18s %-32s %9s\t%s\n", 'Character', 'Name', 'Unicode', 'UTF-8 encoding (hex)'), '-' x 84;
 
for < A ö Ж € 𝄞 😜 > -> $char {
printf " %-7s %-43s U+%04s\t%12s\n", $char, $char.uniname,
$char.ord.base(16), $char.encode('UTF8').list».base(16).Str
}</lang>
{{out}}
<pre>Character Name Unicode UTF-8 encoding (hex)
------------------------------------------------------------------------------------
A LATIN CAPITAL LETTER A U+0041 41
ö LATIN SMALL LETTER O WITH DIAERESIS U+00F6 C3 B6
Ж CYRILLIC CAPITAL LETTER ZHE U+0416 D0 96
€ EURO SIGN U+20AC E2 82 AC
𝄞 MUSICAL SYMBOL G CLEF U+1D11E F0 9D 84 9E
😜 FACE WITH STUCK-OUT TONGUE AND WINKING EYE U+1F61C F0 9F 98 9C</pre>
10,333

edits