CharacterArray.st
changeset 4244 5deefa3144fb
parent 4156 3079a5a94617
child 4294 9742a8b53d50
equal deleted inserted replaced
4243:f3b0d72d598e 4244:5deefa3144fb
  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 
  5292 ! !
  5324 ! !
  5293 
  5325 
  5294 !CharacterArray class methodsFor:'documentation'!
  5326 !CharacterArray class methodsFor:'documentation'!
  5295 
  5327 
  5296 version
  5328 version
  5297     ^ '$Header: /cvs/stx/stx/libbasic/CharacterArray.st,v 1.159 1999-05-08 14:32:08 cg Exp $'
  5329     ^ '$Header: /cvs/stx/stx/libbasic/CharacterArray.st,v 1.160 1999-05-31 10:41:12 cg Exp $'
  5298 ! !
  5330 ! !
  5299 CharacterArray initialize!
  5331 CharacterArray initialize!