4 Replies Latest reply on Oct 12, 2006 8:34 AM by Newsgroup_User

    saving text with FileIO

    Level 7
      I'm opening a text file with the fileIO Xtra and then I want to save to
      that text file. But, I want to do a search and replace. It's just going
      to be replacing one line but I'm not sure how to go about doing it.

      Any advice would eb appreciated.

      Thanks.

        • 1. Re: saving text with FileIO
          Level 7
          Open the file using fileIO, dump the contents of the file into a
          variable in your movie. Search for the line that you want to replace in
          the variable, you can use "contains", or string matching, or "offset",
          or the line number, if you know it, to find the text to be replaced.
          Once found, delete the existing line, and add your new line, set the
          text of the file to the contents of this variable.

          --
          Rob
          _______
          Rob Dillon
          Adobe Community Expert
          http://www.ddg-designs.com
          412-243-9119

          http://www.macromedia.com/software/trial/
          • 2. Re: saving text with FileIO
            Level 7
            Rob, Thanks for the answer.

            I have managed to find the line using a repeat loop roughly in the
            following format :
            repeat with x = 1 to the number of lines in fullText -- fullText is my
            text variable as you suggested
            if fullText.line[x] contains myText then
            fullText.line[x] = newText
            end if
            end repeat

            I get a script error with the above saying the line 'fullText.line[x] =
            newText' is the wrong type. First, what's the Lingo to delete a line? Annd
            second, what's the Lingo to add a line? I'd like to add the new line in the
            same location as the old one. But would also like to know how to add a new
            line to the end.

            • 3. Re: saving text with FileIO
              Level 7
              You have to treat text in a variable as if it was a field. Further, you
              have to use verbose lingo.

              To delete a chunk of text in a variable, you can use:

              delete variableName.line[X]

              This will remove the line of text. If you had blank lines between
              paragraphs you will now have a double blank line between the two
              paragraphs that were above and below the line that you deleted.

              Remember that Director counts lines as those text chunks delimited by
              carriage returns, not periods.

              To put in new text where the old text was use:

              put newString after variableName.line[Y]

              Depending on how your text is formatted, you may need to use:

              put RETURN & newString after variableName.line[Y]

              --
              Rob
              _______
              Rob Dillon
              Adobe Community Expert
              http://www.ddg-designs.com
              412-243-9119

              http://www.macromedia.com/software/trial/
              • 4. Re: saving text with FileIO
                Level 7
                Rob, Thanks very much for that. I now have it working. I guess to add text
                at the end wouldn't be too hard, I just insert it after 'the number of
                lines' of the text variable.

                You have been a great help. Much appreciated.