2078 '12345678901234567890' replChar:$0 withString:'foo' |
2078 '12345678901234567890' replChar:$0 withString:'foo' |
2079 'a string with spaces' replChar:$ withString:' foo ' |
2079 'a string with spaces' replChar:$ withString:' foo ' |
2080 " |
2080 " |
2081 ! |
2081 ! |
2082 |
2082 |
|
2083 replString:subString withString:newString |
|
2084 "return a copy of the receiver, with all sequences of subString replaced |
|
2085 by newString (i.e. slice in the newString in place of the oldString)." |
|
2086 |
|
2087 |tmpStream idx idx1| |
|
2088 |
|
2089 tmpStream := WriteStream on:(self class new). |
|
2090 idx := 1. |
|
2091 [idx ~~ 0] whileTrue:[ |
|
2092 idx1 := idx. |
|
2093 idx := self indexOfSubCollection:subString startingAt:idx. |
|
2094 idx ~~ 0 ifTrue:[ |
|
2095 tmpStream nextPutAll:(self copyFrom:idx1 to:idx-1). |
|
2096 tmpStream nextPutAll:newString. |
|
2097 idx := idx + subString size |
|
2098 ] |
|
2099 ]. |
|
2100 tmpStream nextPutAll:(self copyFrom:idx1). |
|
2101 ^ tmpStream contents |
|
2102 |
|
2103 " |
|
2104 '12345678901234567890' replString:'123' withString:'OneTwoThree' |
|
2105 '12345678901234567890' replString:'123' withString:'*' |
|
2106 '12345678901234567890' replString:'234' withString:'foo' |
|
2107 |
|
2108 ('a string with spaces' replChar:$ withString:' foo ') |
|
2109 replString:'foo' withString:'bar' |
|
2110 " |
|
2111 |
|
2112 "Modified: / 31.5.1999 / 12:33:59 / cg" |
|
2113 ! |
|
2114 |
2083 trimBlanks |
2115 trimBlanks |
2084 "return a copy of the receiver without leading |
2116 "return a copy of the receiver without leading |
2085 and trailing spaces. |
2117 and trailing spaces. |
2086 This is an ST/V compatibility method." |
2118 This is an ST/V compatibility method." |
2087 |
2119 |