File tree Expand file tree Collapse file tree 1 file changed +5
-6
lines changed
categories/cookbook/01strings Expand file tree Collapse file tree 1 file changed +5
-6
lines changed Original file line number Diff line number Diff line change 6
6
7
7
= AUTHOR Scott Penrose
8
8
9
- You want to convert characters to their numeric value or vice-versa
9
+ You want to convert characters to their codepoint number value or vice-versa
10
10
11
11
= end pod
12
12
13
- # XXX I'm not sure "numeric value" is still correct for utf-8, as the actual
14
- # value(s) in memory can be very different. Maybe use "codepoint", or "codepoint
15
- # number"?
16
-
17
13
my $ char = ' a' ;
18
14
my $ num = $ char . ord ;
19
15
say $ num ;
20
16
my $ char2 = $ num . chr ;
21
17
say $ char2 ;
18
+ my $ copyright = ' ©' ;
19
+ say $ copyright ~ " : " ~ $ copyright . ord ~ " : " ~ $ copyright . ord . chr ;
22
20
23
21
$ char = ' foo' ;
24
- say $ char . ord ; # XXX is this correct behavior?
22
+ # ord returns the codepoint of the first char in a string
23
+ say $ char ~ " : " ~ $ char . ord ;
25
24
26
25
# vim: expandtab shiftwidth=4 ft=perl6
You can’t perform that action at this time.
0 commit comments