File tree Expand file tree Collapse file tree 2 files changed +43
-0
lines changed
categories/cookbook/01strings Expand file tree Collapse file tree 2 files changed +43
-0
lines changed Original file line number Diff line number Diff line change
1
+ use v6 ;
2
+
3
+ = begin pod
4
+
5
+ = TITLE Reversing a String by Word or Character
6
+
7
+ = AUTHOR stmuk
8
+
9
+ You want to reverse words or characters in a string
10
+
11
+ = end pod
12
+
13
+ my $ string = " The Magic Words are Squeamish Ossifrage" ;
14
+
15
+ # reverse the characters in a scalar
16
+
17
+ say $ string . flip ;
18
+
19
+ # reverse the words in a scalar
20
+
21
+ say $ string . split (" " ). reverse ;
22
+
23
+ # vim: expandtab shiftwidth=4 ft=perl6
Original file line number Diff line number Diff line change
1
+ use v6 ;
2
+
3
+ = begin pod
4
+
5
+ = TITLE Trimming whitespace from both ends of a string
6
+
7
+ = AUTHOR stmuk
8
+
9
+ You have a string with leading and/or trailing whitespace
10
+ you wish to remove
11
+
12
+ = end pod
13
+
14
+ my $ string = " \t the cat sat on the mat " ;
15
+
16
+ $ string .= trim ;
17
+
18
+ say : $ string . perl ;
19
+
20
+ # vim: expandtab shiftwidth=4 ft=perl6
You can’t perform that action at this time.
0 commit comments