Skip to content

Commit 35e6998

Browse files
authored
amplify the substr-rw examples
1 parent 5ba57ef commit 35e6998

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

doc/Type/Str.pod6

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -903,14 +903,21 @@ one does this:
903903
904904
my $string = "abc";
905905
$string.substr-rw(1, 1) = "z";
906-
$string.say; # OUTPUT: «azc␤»
906+
$string.say; # OUTPUT: «azc␤»
907+
908+
Note that new characters can be inserted as well:
907909
908-
C<substr-rw> also has a function form, so the above example can also be
910+
$string.substr-rw(2, 0) = "-Zorro-"; # insert new characters BEFORE the character at index 2
911+
$string.say; # OUTPUT: «az-Zorro-c␤»
912+
913+
C<substr-rw> also has a function form, so the above examples can also be
909914
written like so:
910915
911916
my $string = "abc";
912917
substr-rw($string, 1, 1) = "z";
913-
$string.say; # OUTPUT: «azc␤»
918+
$string.say; # OUTPUT: «azc␤»
919+
substr-rw($string, 2, 0) = "-Zorro-";
920+
$string.say; # OUTPUT: «az-Zorro-c␤»
914921
915922
It is also possible to alias the writable reference returned by C<substr-rw>
916923
for repeated operations:

0 commit comments

Comments
 (0)