2 Replies Latest reply on Nov 27, 2006 12:00 PM by golem2

    clear string in a file

    golem2
      Hi,
      How can I clear a string in a file?
      if the file had: "One two three" and I want to replace it with "cat dog".

      Thanks
        • 1. Re: clear string in a file
          duckets Level 1

          Use the fileIO xtra to delete and re-create the file, before writing your new string. Otherwise, if your new string is shorter than the old file, you will end up with the remains of the old file persisting:


          fileio = xtra("fileio").new()
          myFile = _movie.path & "myFileName.txt"

          fileio.openFile(myFile,0)
          fileio.delete()
          fileio.createFile(myFile)
          fileio.openFile(myFile,0)
          fileio.writestring("cat dog")
          fileio.closeFile()

          fileio = void


          hope this helps!

          - Ben
          • 2. Re: clear string in a file
            golem2 Level 1
            thanks duckets