1 Reply Latest reply on Feb 26, 2007 3:49 AM by Newsgroup_User

    Getting the new line, enter or \n in file

    ajeet.ghule Level 1
      Hi :-)

      I am reading a file.I want ot find out if there is newline in the file.how do i do it in director.
      Please let me know

      Thanks
        • 1. Re: Getting the new line, enter or \n in file
          Level 7
          ajeet.ghule wrote:
          > I am reading a file.I want ot find out if there is newline in the
          > file.how do i do it in director. Please let me know

          If the file is not too large (less than 1MB, say - test for suitability),
          read it all into a string variable (the getNetText function can be used) and
          use the Lingo "contains" function.

          If the file is larger than that, you'll be better off speed-wise using an
          xtra, like the free pregex xtra from http://openxtras.org/pregex/.

          What do you want to do with the information? If you want to make sure all
          possible line ending characters get changed to \n, then you can use
          something like

          data = PRegEx_ReadEntireFile(sourceFile)
          if not listP(data) or not stringP(data[1]) then
          put "Read failure of " & src
          halt
          end if

          -- change all line-ends to \n
          PRegEx_Replace(data, "(?:\x0D\x0A)|[\x0D\x0A]", "g", "\n")

          -- data[1] now contains the string you want.

          Andrew