1. ----------------------------------------
  2. -- replace in string
  3. -- optionally replace with JS version based on RegExp
  4. ----------------------------------------
  5. on str_replace (stringToFind, stringToInsert, input)
  6.   output = ""
  7.   findLen = stringToFind.length - 1
  8.   repeat while true
  9.     currOffset = offset(stringToFind, input)
  10.     if currOffset=0 then exit repeat
  11.     put input.char [1..currOffset] after output
  12.     delete the last char of output
  13.     put stringToInsert after output
  14.     delete input.char [1.. (currOffset + findLen)]
  15.   end repeat
  16.   put input after output
  17.   return output
  18. end
[raw code]