Skip to content

Commit e7a4202

Browse files
committed
more Str examples
1 parent 68c9352 commit e7a4202

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

lib/Str.pod

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,13 @@ C<$limit> matches.
199199
If no matcher is supplied, a list of characters in the string
200200
(ie C<$delimiter = rx/./>) is returned.
201201
202+
Examples:
203+
204+
comb(/\w/, "a;b;c").perl; # ("a", "b", "c").list
205+
comb(/\N/, "a;b;c").perl; # ("a", ";", "b", ";", "c").list
206+
comb(/\w/, "a;b;c", 2).perl; # ("a", "b").list
207+
comb(/\w\;\w/, "a;b;c", 2).perl; # ("a;b",).list
208+
202209
=head2 lines
203210
204211
multi sub lines(Str:D $input, $limit = Inf) returns Positional
@@ -207,6 +214,14 @@ If no matcher is supplied, a list of characters in the string
207214
Returns a list of lines (without trailing newline characters), i.e. the
208215
same as a call to C<$input.comb( / ^^ \N* /, $limit )> would.
209216
217+
Examples:
218+
219+
lines("a\nb").perl; # ("a", "b").list
220+
lines("a\nb").elems; # 2
221+
"a\nb".lines.elems; # 2
222+
223+
"a\n".lines.elems; # 1
224+
210225
=head2 words
211226
212227
multi sub words(Str:D $input, $limit = Inf) returns Positional
@@ -215,13 +230,25 @@ same as a call to C<$input.comb( / ^^ \N* /, $limit )> would.
215230
Returns a list of non-whitespace bits, i.e. the same as a call to
216231
C<$input.comb( / \S+ /, $limit )> would.
217232
233+
Examples:
234+
235+
"a\nb\n".words.perl; # ("a", "b").list
236+
"hello world".words.perl; # ("hello", "world").list
237+
"foo:bar".words.perl; # ("foo:bar",).list
238+
"foo:bar\tbaz".words.perl; # ("foo:bar", "baz").list
239+
218240
=head2 flip
219241
220242
multi sub flip(Str:D ) returns Str:D
221243
multi method flip(Str:D:) returns Str:D
222244
223245
Returns the string reversed character by character.
224246
247+
Examples:
248+
249+
"Perl".flip; # lreP
250+
"ABBA".flip; # ABBA
251+
225252
=head2 sprintf
226253
227254
multi sub sprintf ( Str:D $format, *@args) returns Str:D
@@ -297,6 +324,13 @@ Examples:
297324
Returns a part of the string, starting from the character with index C<$from>
298325
(where the first character has index 0) and with length C<$chars>.
299326
327+
Examples:
328+
329+
substr("Long string", 6, 3); # tri
330+
substr("Long string", 6); # tring
331+
substr("Long string", 6, *-1); # trin
332+
substr("Long string", *-3, *-1); # in
333+
300334
=head2 succ
301335
302336
method succ(Str:D) returns Str:D

0 commit comments

Comments
 (0)