function replaceString str, pattern, newStr
  put empty into retVal
  put length( pattern ) -1 into len
  put offset( pattern, str ) into offs
  repeat while offs <> 0
    put char 1 to (offs -1) of str & newStr after retVal
    delete char 1 to (offs +len) of str
    put offset( pattern, str ) into offs
  end repeat
  return retVal & str -- in case there's something after the last foundChunk
end replaceString