Converting between characters and numbers.
You want to convert characters to their codepoint number value or vice-versa
#!/usr/bin/env raku
use v6;
my $char = 'a';
my $num = $char.ord;
say $num;
my $char2 = $num.chr;
say $char2;
my $copyright = 'Ā©';
say $copyright ~ " : " ~ $copyright.ord ~ " : " ~ $copyright.ord.chr;
$char = 'foo';
# ords returns the codepoints of all char in a string
say $char ~ " : " ~ $char.ords;
# vim: expandtab shiftwidth=4 ft=perl6
See Also
01strings
Raku Cookbook: Introduction to Strings
01strings
Reversing a String by Word or Character
01strings
Trimming whitespace from both ends of a string
04arrays
Specifying a list in your program
The Camelia image is copyright 2009 by Larry Wall. "Raku" is a trademark of the Yet Another Society.
All rights reserved.
Built with Podlite ā the markup and publishing tools behind this site.