Skip to content

Commit 68c9352

Browse files
committed
add some Str examples
1 parent 73e7393 commit 68c9352

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

lib/Str.pod

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,16 @@ Searches for C<$needle> in the string starting from C<$startpos>. It returns
131131
the offset into the string where C<$needle> was found, and an undefined value
132132
if it was not found.
133133
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+
134144
=head2 rindex
135145
136146
multi sub rindex(Str:D $haystack, Str:D $needle, Int $startpos = $haystack.chars) returns StrPos
@@ -139,6 +149,11 @@ if it was not found.
139149
Returns the last position of C<$needle> in C<$haystack> not after C<$startpos>.
140150
Returns an undefined value if C<$needle> wasn't found.
141151
152+
Examples:
153+
154+
say rindex "Camelia is a butterfly", "a"; # 11
155+
say rindex "Camelia is a butterfly", "a", 10; # 6
156+
142157
=head2 split
143158
144159
multi sub split( Str:D $delimiter, Str:D $input, $limit = Inf, :$all) returns Positional
@@ -158,6 +173,17 @@ are included in the result list.
158173
Note that unlike in Perl 5, empty chunks are not removed from the result list.
159174
If you want that behavior, consider using C<Str.comb> instead.
160175
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+
161187
=head2 comb
162188
163189
multi sub comb(Str:D $matcher, Str:D $input, $limit = Inf, Bool :$match)

0 commit comments

Comments
 (0)