3 Replies Latest reply on May 10, 2007 2:40 PM by Newsgroup_User

    writereturn or workaround?

    walfridson Level 1
      Googling, trying to find some usefull info how to use writereturn()
      I have a textmember with some text, opening the saved file looks wrong in notepad. No new lines.
      Now I simply write the file like this:
      writeString(fileObj,member("mytext").text)

      all lingo
      cheers
        • 1. Re: writereturn or workaround?
          Level 7
          > Googling, trying to find some usefull info how to use writereturn()

          If you execute the following from your message window:
          put interface(xtra "FileIO")
          one of the output lines is:
          writeReturn object me, symbol platform -- Inserts #unix, #macintosh or
          #windows platform line return.

          However, using this method relies on you writing out your text line by
          line rather than as an entire "lump"

          You could use a regular expression via JavaScript or the PRegEx xtra to
          replace RETURN characters with CRLF. One advantage of the (free) PRegEx
          xtra is that it will also write to disk with a single line of code.
          Here's a little handler that might help (requires PRegEx
          < http://www.openxtras.org>):
          --
          on mWriteDOSString aString, aPath
          l = [aString]
          nFound = re_replace(l, "(\x0D)(?!\x0A)", "g", "\x0D\x0A")
          if nFound < 0 then alert("Error:" && PRegEx_DescribeError())
          nWritten = re_write(aPath, l)
          if nWritten < 0 then alert("Error:" && PRegEx_DescribeError())
          end
          • 2. Re: writereturn or workaround?
            walfridson Level 1
            Thanks for your help Sean
            http://www.mediamacros.com/item/item-950637601/ just found this little snippet which worked
            • 3. Re: writereturn or workaround?
              Level 7
              > http://www.mediamacros.com/item/item-950637601/ just found this little snippet which worked

              By the look of it, the script you referred to reads in a DOS-formatted
              string and removes the LF character so that you can display the results
              in a #text/#field sprite - essentially translating CRLF into CR. Here's
              a handler that uses PRegEx to do the same:
              --
              on mReadDOSString aPath
              tList = re_read(aPath)
              if ilk(tList, #list) = 0 then
              -- error
              alert("Error reading file:" && PRegEx_DescribeError())
              exit
              end if
              nReplaced = re_replace(tList, "(\x0D\x0A)", "g", "\x0D")
              if nReplaced < 0 then alert("Error in translation:" &&
              PRegEx_DescribeError())
              return tList[1]
              end