@@ -131,6 +131,16 @@ Searches for C<$needle> in the string starting from C<$startpos>. It returns
131
131
the offset into the string where C < $needle > was found, and an undefined value
132
132
if it was not found.
133
133
134
+ Examples:
135
+
136
+ say index "Camelia is a butterfly", "a"; # 1
137
+ say index "Camelia is a butterfly", "a", 2; #6
138
+ say index "Camelia is a butterfly", "er"; # 17
139
+ say index "Camelia is a butterfly", "Camel"; # 0
140
+ say index "Camelia is a butterfly", "Onion"; # Int()
141
+
142
+ say index("Camelia is a butterfly", "Onion") ?? 'OK' !! 'NOT'; # NOT
143
+
134
144
= head2 rindex
135
145
136
146
multi sub rindex(Str:D $haystack, Str:D $needle, Int $startpos = $haystack.chars) returns StrPos
@@ -139,6 +149,11 @@ if it was not found.
139
149
Returns the last position of C < $needle > in C < $haystack > not after C < $startpos > .
140
150
Returns an undefined value if C < $needle > wasn't found.
141
151
152
+ Examples:
153
+
154
+ say rindex "Camelia is a butterfly", "a"; # 11
155
+ say rindex "Camelia is a butterfly", "a", 10; # 6
156
+
142
157
= head2 split
143
158
144
159
multi sub split( Str:D $delimiter, Str:D $input, $limit = Inf, :$all) returns Positional
@@ -158,6 +173,17 @@ are included in the result list.
158
173
Note that unlike in Perl 5, empty chunks are not removed from the result list.
159
174
If you want that behavior, consider using C < Str.comb > instead.
160
175
176
+ Examples:
177
+
178
+ say split(';', "a;b;c").perl; # ("a", "b", "c").list
179
+ say split(';', "a;b;c", :all).perl; # ("a", ";", "b", ";", "c").list
180
+ say split(';', "a;b;c", 2).perl; # ("a", "b;c").list
181
+ say split(';', "a;b;c", 2, :all).perl; #("a", ";", "b;c").list
182
+
183
+ say split(';', "a;b;c,d").perl; # ("a", "b", "c,d").list
184
+ say split(/\;/, "a;b;c,d").perl; # ("a", "b", "c,d").list
185
+ say split(/<[;,]>/, "a;b;c,d").perl; # ("a", "b", "c", "d").list
186
+
161
187
= head2 comb
162
188
163
189
multi sub comb(Str:D $matcher, Str:D $input, $limit = Inf, Bool :$match)
0 commit comments