[svn:parrot] r46108 - in trunk: examples/tutorial t/examples

mikehh at svn.parrot.org mikehh at svn.parrot.org
Wed Apr 28 15:43:41 UTC 2010


Author: mikehh
Date: Wed Apr 28 15:43:41 2010
New Revision: 46108
URL: https://trac.parrot.org/parrot/changeset/46108

Log:
add a replace op and document the addition

Modified:
   trunk/examples/tutorial/23_string_ops_substr.pir
   trunk/t/examples/tutorial.t

Modified: trunk/examples/tutorial/23_string_ops_substr.pir
==============================================================================
--- trunk/examples/tutorial/23_string_ops_substr.pir	Wed Apr 28 12:25:40 2010	(r46107)
+++ trunk/examples/tutorial/23_string_ops_substr.pir	Wed Apr 28 15:43:41 2010	(r46108)
@@ -1,4 +1,4 @@
-# Copyright (C) 2007-2009, Parrot Foundation.
+# Copyright (C) 2007-2010, Parrot Foundation.
 # $Id$
 
 =head1 String Operations (continued)
@@ -10,17 +10,28 @@
 position is left out, C<substr> returns all the characters until the
 end of the string.
 
+C<substr> no longer provides an in-place replace, however there is a
+C<replace> operator that allows this type of operation to be performed,
+although not in-place.  The C<replace> operator assigns a new_srting,
+taking as arguments, the old_string, a start and end position, and a
+string to be inserted in between the start and end positions.
+
 =cut
 
 .sub main :main
 
-    $S0 = substr "abcde", 1, 2    # "bc"
-    say $S0
+    $S0 = substr "abcde", 1, 2
+    say $S0                         # "bc"
 
     set $S1, "abcde"
     $S0 = substr $S1, 1, 2
-    say $S0                   # "bc"
-    say $S1                   # "abcde"
+    say $S0                         # "bc"
+    say $S1                         # "abcde"
+
+    set $S1, "abcde"
+    $S0 = replace $S1, 1, 2, "XYZ"
+    say $S0                         # "aXYZde"
+    say $S1                         # "abcde"
 
 .end
 
@@ -29,4 +40,3 @@
 #   fill-column: 100
 # End:
 # vim: expandtab shiftwidth=4 ft=pir:
-

Modified: trunk/t/examples/tutorial.t
==============================================================================
--- trunk/t/examples/tutorial.t	Wed Apr 28 12:25:40 2010	(r46107)
+++ trunk/t/examples/tutorial.t	Wed Apr 28 15:43:41 2010	(r46108)
@@ -97,8 +97,8 @@
 bc
 bc
 abcde
-bc
 aXYZde
+abcde
 END_EXPECTED
 
     '24_string_ops_clone.pir' => << 'END_EXPECTED',


More information about the parrot-commits mailing list