Product Site

5.1.7.50. changeStr

Returns a copy of the receiver object in which newneedle replaces occurrences of needle.

If count is not specified, all occurrences of needle are replaced. If count is specified, it must be a non-negative, whole number that gives the maximum number of occurrences to be replaced.

Here are some examples:
Example 5.88. String class — changeStr method
Say 101100~changeStr("1","")     --    "000"
Say 101100~changeStr("1","X")    --    "X0XX00"
Say 101100~changeStr("1","X",1)  --    "X01100"

-- a Quine: will print an exact copy of itself
-- (see https://en.wikipedia.org/wiki/Quine_%28computing%29)
r=";say'r=.'r'.'r~changeStr(.,'22'x,2)";say'r="'r'"'r~changeStr(.,'22'x,2)