Loading ...
Sorry, an error occurred while loading the content.

Re: [Clip] removing blank lines at start and end of a variable

Expand Messages
  • hsavage
    ... Don, Have you found a suitable method to do the above, if not I ve devised 2 clip methods for the job? The first should work regardless of filesize, it
    Message 1 of 16 , Sep 7, 2005
    • 0 Attachment
      Don - htmlfixit.com wrote:
      > if I have a variable that contains this
      >
      > blank line
      > blank line
      > this is a fine day
      > blank line
      > this is a tuesday
      > blank line
      > blank line
      >
      > and I want to remove the first and last two blank lines ... but leave
      > any blank lines within the content ...
      > what is the best way I should go about this? Regex? Is there a trim
      > function that would do it?
      >
      > Thanks in advance.

      Don,

      Have you found a suitable method to do the above, if not I've devised 2
      clip methods for the job?

      The first should work regardless of filesize, it only deals with the
      start and end lines, the second is dependant on selecting the entire
      file. This could possibly exceed NoteTabs internal Selection or
      Paragraph limits with a very large file.

      With either clip un-commenting the ^!Replace line will ensure there are
      no 'extra' blank lines between paragraphs.


      H="Xblanklines"
      ^!Set %ww%=^$IsWordWrap$
      ^!SetWordWrap 0
      ;^!Replace {\n\n}\n+ >> \1 WRSA
      ^!Jump 1
      :LOOP_TOP
      ^!If "^$GetLine$" = "" ^!DeleteLine
      ^!If "^$GetLine$" <> "" NEXT ELSE LOOP_TOP
      ^!Jump DOC_END
      :LOOP_END
      ^!If "^$GetLine$" = "" ^!KeyBoard BACKSPACE
      ^!If "^$GetLine$" <> "" NEXT ELSE LOOP_END
      ^!InsertText ^%nl%
      ^!SetWordWrap ^%ww%


      H="Xblanklines1"
      ^!Set %ww%=^$IsWordWrap$
      ^!SetWordWrap 0
      ;^!Replace {\n\n}\n+ >> \1 WRSA
      ^!Select ALL
      ^$StrTrim("^$GetSelection$")$
      ^!Jump TEXT_END
      ^!InsertText ^%nl%
      ^!SetWordWrap ^%ww%

      ºvº
      05.09.07
      hrs > hsavage@...
    • Don - htmlfixit.com
      ... Thanks for your continued efforts on this. I have not solved it yet. The prior suggestion assumed that I had just two lines of text. That is a fair
      Message 2 of 16 , Sep 7, 2005
      • 0 Attachment
        hsavage wrote:
        > Don - htmlfixit.com wrote:
        > > if I have a variable that contains this
        > >
        > > blank line
        > > blank line
        > > this is a fine day
        > > blank line
        > > this is a tuesday
        > > blank line
        > > blank line
        > >
        > > and I want to remove the first and last two blank lines ... but leave
        > > any blank lines within the content ...
        > > what is the best way I should go about this? Regex? Is there a trim
        > > function that would do it?
        > >
        > > Thanks in advance.
        >
        > Don,
        >
        > Have you found a suitable method to do the above, if not I've devised 2
        > clip methods for the job?
        >
        > The first should work regardless of filesize, it only deals with the
        > start and end lines, the second is dependant on selecting the entire
        > file. This could possibly exceed NoteTabs internal Selection or
        > Paragraph limits with a very large file.
        >
        > With either clip un-commenting the ^!Replace line will ensure there are
        > no 'extra' blank lines between paragraphs.
        >
        >
        > H="Xblanklines"
        > ^!Set %ww%=^$IsWordWrap$
        > ^!SetWordWrap 0
        > ;^!Replace {\n\n}\n+ >> \1 WRSA
        > ^!Jump 1
        > :LOOP_TOP
        > ^!If "^$GetLine$" = "" ^!DeleteLine
        > ^!If "^$GetLine$" <> "" NEXT ELSE LOOP_TOP
        > ^!Jump DOC_END
        > :LOOP_END
        > ^!If "^$GetLine$" = "" ^!KeyBoard BACKSPACE
        > ^!If "^$GetLine$" <> "" NEXT ELSE LOOP_END
        > ^!InsertText ^%nl%
        > ^!SetWordWrap ^%ww%
        >
        >
        > H="Xblanklines1"
        > ^!Set %ww%=^$IsWordWrap$
        > ^!SetWordWrap 0
        > ;^!Replace {\n\n}\n+ >> \1 WRSA
        > ^!Select ALL
        > ^$StrTrim("^$GetSelection$")$
        > ^!Jump TEXT_END
        > ^!InsertText ^%nl%
        > ^!SetWordWrap ^%ww%
        >
        Thanks for your continued efforts on this. I have not solved it yet.
        The prior suggestion assumed that I had just two lines of text. That is
        a fair (though inacurate) assumption based upon my question. What I did
        is take a file that may look like this:

        blank line
        blank line
        text
        text
        blankline
        text
        text
        blankline
        blankline
        dividing point:delimiter
        blank line
        text
        text
        blankline
        text
        text
        blankline
        blankline
        dividing point:delimiter
        blank line
        blank line
        blank line
        text
        text
        blankline
        text
        text
        blankline
        blankline
        blankline

        The number of blank lines before or after the content is varied. So
        simple search and replaces don't work. I have already taken the file
        and stepped through it so that in step one, the first part before the
        first dividing line/delimiter is loaded into a variable. I then save
        that variable to a new file. Before saving, however, I want to clean it
        up. I may be able to do it with your clips which I will study after
        saving it. If I could do it before saving it, even better. In fact if
        I could do the file before running my steps on it, maybe that would
        work. I don't know the file size as this is to help another person.
        The sample they sent me was fairly small.

        Double returns between paragraphs aren't my concern, it was the extra
        white space before and after the delimiters that I am trying to get out
        of the variables.

        I'll start working with this suggestion.
      • Jeffery Scism
        slower but why not just replace ^P^P with ^P, and rerun it until no more are found? ~~ Jeffery G. Scism, IBSSG Local Coordinator Representative, NE/NC Region,
        Message 3 of 16 , Sep 7, 2005
        • 0 Attachment
          slower but why not just replace

          ^P^P with ^P, and rerun it until no more are found?

          ~~

          Jeffery G. Scism, IBSSG
          Local Coordinator Representative,
          NE/NC Region, USGenWeb Project

          http://usgenweb.org/





          Don - htmlfixit.com wrote:

          >hsavage wrote:
          >
          >
          >>Don - htmlfixit.com wrote:
          >> > if I have a variable that contains this
          >> >
          >> > blank line
          >> > blank line
          >> > this is a fine day
          >> > blank line
          >> > this is a tuesday
          >> > blank line
          >> > blank line
          >> >
          >> > and I want to remove the first and last two blank lines ... but leave
          >> > any blank lines within the content ...
          >> > what is the best way I should go about this? Regex? Is there a trim
          >> > function that would do it?
          >> >
          >> > Thanks in advance.
          >>
          >>Don,
          >>
          >>Have you found a suitable method to do the above, if not I've devised 2
          >>clip methods for the job?
          >>
          >>The first should work regardless of filesize, it only deals with the
          >>start and end lines, the second is dependant on selecting the entire
          >>file. This could possibly exceed NoteTabs internal Selection or
          >>Paragraph limits with a very large file.
          >>
          >>With either clip un-commenting the ^!Replace line will ensure there are
          >>no 'extra' blank lines between paragraphs.
          >>
          >>
          >>H="Xblanklines"
          >>^!Set %ww%=^$IsWordWrap$
          >>^!SetWordWrap 0
          >>;^!Replace {\n\n}\n+ >> \1 WRSA
          >>^!Jump 1
          >>:LOOP_TOP
          >>^!If "^$GetLine$" = "" ^!DeleteLine
          >>^!If "^$GetLine$" <> "" NEXT ELSE LOOP_TOP
          >>^!Jump DOC_END
          >>:LOOP_END
          >>^!If "^$GetLine$" = "" ^!KeyBoard BACKSPACE
          >>^!If "^$GetLine$" <> "" NEXT ELSE LOOP_END
          >>^!InsertText ^%nl%
          >>^!SetWordWrap ^%ww%
          >>
          >>
          >>H="Xblanklines1"
          >>^!Set %ww%=^$IsWordWrap$
          >>^!SetWordWrap 0
          >>;^!Replace {\n\n}\n+ >> \1 WRSA
          >>^!Select ALL
          >>^$StrTrim("^$GetSelection$")$
          >>^!Jump TEXT_END
          >>^!InsertText ^%nl%
          >>^!SetWordWrap ^%ww%
          >>
          >>
          >>
          >Thanks for your continued efforts on this. I have not solved it yet.
          >The prior suggestion assumed that I had just two lines of text. That is
          >a fair (though inacurate) assumption based upon my question. What I did
          >is take a file that may look like this:
          >
          >blank line
          >blank line
          >text
          >text
          >blankline
          >text
          >text
          >blankline
          >blankline
          >dividing point:delimiter
          >blank line
          >text
          >text
          >blankline
          >text
          >text
          >blankline
          >blankline
          >dividing point:delimiter
          >blank line
          >blank line
          >blank line
          >text
          >text
          >blankline
          >text
          >text
          >blankline
          >blankline
          >blankline
          >
          >The number of blank lines before or after the content is varied. So
          >simple search and replaces don't work. I have already taken the file
          >and stepped through it so that in step one, the first part before the
          >first dividing line/delimiter is loaded into a variable. I then save
          >that variable to a new file. Before saving, however, I want to clean it
          >up. I may be able to do it with your clips which I will study after
          >saving it. If I could do it before saving it, even better. In fact if
          >I could do the file before running my steps on it, maybe that would
          >work. I don't know the file size as this is to help another person.
          >The sample they sent me was fairly small.
          >
          >Double returns between paragraphs aren't my concern, it was the extra
          >white space before and after the delimiters that I am trying to get out
          >of the variables.
          >
          >I'll start working with this suggestion.
          >
          >
          >
          >
          >Fookes Software: http://www.fookes.us, http://www.fookes.com
          >Fookes Software Mailing Lists: http://www.fookes.us/maillist.htm
          >
          >Yahoo! Groups Links
          >
          >
          >
          >
          >
          >
          >
          >
          >
          >


          [Non-text portions of this message have been removed]
        • hsavage
          ... Don, dividing point:delimiter - What is this delimiter? Is it the same character or string of characters in every case? Offhand, it looks as if this
          Message 4 of 16 , Sep 7, 2005
          • 0 Attachment
            Don - htmlfixit.com wrote:
            > hsavage wrote:
            >>
            >> Have you found a suitable method to do the above, if not I've devised 2
            >> clip methods for the job?
            >>
            >> The first should work regardless of filesize, it only deals with the
            >> start and end lines, the second is dependant on selecting the entire
            >> file. This could possibly exceed NoteTabs internal Selection or
            >> Paragraph limits with a very large file.
            >>
            >> With either clip un-commenting the ^!Replace line will ensure there are
            >> no 'extra' blank lines between paragraphs.
            >>
            >>
            > Thanks for your continued efforts on this. I have not solved it yet.
            > The prior suggestion assumed that I had just two lines of text. That is
            > a fair (though inacurate) assumption based upon my question. What I did
            > is take a file that may look like this:
            >
            > blank line
            > blank line
            > text
            > text
            > blankline
            > text
            > text
            > blankline
            > blankline
            > dividing point:delimiter
            > blank line
            > text
            > text
            >
            > The number of blank lines before or after the content is varied. So
            > simple search and replaces don't work. I have already taken the file
            > and stepped through it so that in step one, the first part before the
            > first dividing line/delimiter is loaded into a variable. I then save
            > that variable to a new file. Before saving, however, I want to clean it
            > up. I may be able to do it with your clips which I will study after
            > saving it. If I could do it before saving it, even better. In fact if
            > I could do the file before running my steps on it, maybe that would
            > work. I don't know the file size as this is to help another person.
            > The sample they sent me was fairly small.
            >
            > Double returns between paragraphs aren't my concern, it was the extra
            > white space before and after the delimiters that I am trying to get out
            > of the variables.
            >
            > I'll start working with this suggestion.

            Don,

            'dividing point:delimiter' - What is this delimiter? Is it the same
            character or string of characters in every case?

            Offhand, it looks as if this clip would be best(easiest) to modify to
            fill the need.

            H="Xblanklines"
            ^!Set %ww%=^$IsWordWrap$
            ^!SetWordWrap 0
            ;^!Replace {\n\n}\n+ >> \1 WRSA
            ^!Jump 1
            :LEADING
            ^!If "^$GetLine$" = "" ^!DeleteLine
            ^!If "^$GetLine$" <> "" NEXT ELSE LEADING
            ^!Jump DOC_END
            :TRAILING
            ^!If "^$GetLine$" = "" ^!KeyBoard BACKSPACE
            ^!If "^$GetLine$" <> "" NEXT ELSE TRAILING
            ^!InsertText ^%nl%
            ^!SetWordWrap ^%ww%

            ºvº
            05.09.07
            hrs > hsavage@...
          • Don - htmlfixit.com
            ... yes, always the same string of characters is used as the delimiter
            Message 5 of 16 , Sep 7, 2005
            • 0 Attachment
              > Don,
              >
              > 'dividing point:delimiter' - What is this delimiter? Is it the same
              > character or string of characters in every case?
              >
              > Offhand, it looks as if this clip would be best(easiest) to modify to
              > fill the need.
              >
              > H="Xblanklines"
              > ^!Set %ww%=^$IsWordWrap$
              > ^!SetWordWrap 0
              > ;^!Replace {\n\n}\n+ >> \1 WRSA
              > ^!Jump 1
              > :LEADING
              > ^!If "^$GetLine$" = "" ^!DeleteLine
              > ^!If "^$GetLine$" <> "" NEXT ELSE LEADING
              > ^!Jump DOC_END
              > :TRAILING
              > ^!If "^$GetLine$" = "" ^!KeyBoard BACKSPACE
              > ^!If "^$GetLine$" <> "" NEXT ELSE TRAILING
              > ^!InsertText ^%nl%
              > ^!SetWordWrap ^%ww%
              >
              yes, always the same string of characters is used as the delimiter
            • Alec Burgess
              Don/others If part of your sample is : text blankline blankline dividing point:delimiter blank line blank line blank line text then this regexp (not tested)
              Message 6 of 16 , Sep 7, 2005
              • 0 Attachment
                Don/others

                If part of your sample is :
                text
                blankline
                blankline
                dividing point:delimiter
                blank line
                blank line
                blank line
                text

                then this regexp (not tested) should convert it to:

                text
                dividing point:delimiter
                text

                ^!replace "\n+dividing point:delimiter\n+" >> "\ndividing point:delimiter\n"
                rwsait

                Note: if the sample is already:
                text
                dividing point:delimiter
                text
                -- then the above regexp is a no-op and will get hits but not alter what is
                already there.


                subject of course to the main file not being so large that regexp's fail.
                AFAICT, you could put it at either the top or bottom of HRS' earlier clip
                which did not include support for the delimiter and get what you require.



                Regards ... Alec
                --
                ; ( ) { } [ ] \ | 9 0 + = () {} []


                ---- Original Message ----
                From: "Don - htmlfixit.com" <don@...>
                To: <ntb-clips@yahoogroups.com>
                Sent: Wednesday, September 07, 2005 12:12
                Subject: [gla: Re: [Clip] removing blank lines at start and
                end of a variable

                >> Don,
                >>
                >> 'dividing point:delimiter' - What is this delimiter? Is
                >> it the same character or string of characters in every
                >> case?
                >>
                >> Offhand, it looks as if this clip would be best(easiest)
                >> to modify to fill the need.
                >>
                >> H="Xblanklines"
                >> ^!Set %ww%=^$IsWordWrap$
                >> ^!SetWordWrap 0
                >> ;^!Replace {\n\n}\n+ >> \1 WRSA
                >> ^!Jump 1
                >>> LEADING
                >> ^!If "^$GetLine$" = "" ^!DeleteLine
                >> ^!If "^$GetLine$" <> "" NEXT ELSE LEADING
                >> ^!Jump DOC_END
                >>> TRAILING
                >> ^!If "^$GetLine$" = "" ^!KeyBoard BACKSPACE
                >> ^!If "^$GetLine$" <> "" NEXT ELSE TRAILING
                >> ^!InsertText ^%nl%
                >> ^!SetWordWrap ^%ww%
                >>
                > yes, always the same string of characters is used as the
                > delimiter
              • hsavage
                ... point:delimiter n ... what is ... Alec, Don, This regex is now tested. Adding Alec s ^!Replace to one of my earlier attempts and changing the delimiter
                Message 7 of 16 , Sep 7, 2005
                • 0 Attachment
                  Alec Burgess wrote:
                  > Don/others
                  >
                  > then this regexp (not tested) should convert it to:
                  >
                  > text
                  > dividing point:delimiter
                  > text
                  >
                  > ^!replace "\n+dividing point:delimiter\n+" >> "\ndividing
                  point:delimiter\n"
                  > rwsait
                  >
                  > Note: if the sample is already:
                  > text
                  > dividing point:delimiter
                  > text
                  > -- then the above regexp is a no-op and will get hits but not alter
                  what is
                  > already there.
                  >
                  > subject of course to the main file not being so large that regexp's fail.
                  > AFAICT, you could put it at either the top or bottom of HRS' earlier clip
                  > which did not include support for the delimiter and get what you require.
                  >
                  > Regards ... Alec

                  Alec, Don,

                  This regex is now tested. Adding Alec's ^!Replace to one of my earlier
                  attempts and changing the delimiter to the correct characters the clip
                  now works fine on my limited sample.

                  H="Xblanklines"
                  ^!Set %ww%=^$IsWordWrap$
                  ^!SetWordWrap 0
                  ^!Jump 1
                  :LOOP_TOP
                  ^!If "^$GetLine$" = "" ^!DeleteLine
                  ^!If "^$GetLine$" <> "" NEXT ELSE LOOP_TOP
                  ^!Replace "\n+==========\n+" >> "\n==========\n" IWRSA
                  ^!Jump DOC_END
                  :LOOP_END
                  ^!If "^$GetLine$" = "" ^!KeyBoard BACKSPACE
                  ^!If "^$GetLine$" <> "" NEXT ELSE LOOP_END
                  ^!InsertText ^%nl%
                  ^!SetWordWrap ^%ww%

                  Try it, let us know.

                  ºvº
                  05.09.07
                  hrs > hsavage@...
                • hsavage
                  ... fail. ... earlier clip ... require. ... The regex can be shortened somewhat as follows, ^!Replace n+{==========} n+ n 1 n IWRSA ºvº 05.09.07 hrs
                  Message 8 of 16 , Sep 7, 2005
                  • 0 Attachment
                    hsavage wrote:
                    > Alec Burgess wrote:
                    >> Don/others
                    >> subject of course to the main file not being so large that regexp's
                    fail.
                    >> AFAICT, you could put it at either the top or bottom of HRS'
                    earlier clip
                    >> which did not include support for the delimiter and get what you
                    require.
                    >>
                    >> Regards ... Alec
                    >
                    > Alec, Don,
                    >
                    > This regex is now tested. Adding Alec's ^!Replace to one of my earlier
                    > attempts and changing the delimiter to the correct characters the clip
                    > now works fine on my limited sample.
                    >
                    > H="Xblanklines"
                    > ^!Set %ww%=^$IsWordWrap$
                    > ^!SetWordWrap 0
                    > ^!Jump 1
                    > :LOOP_TOP
                    > ^!If "^$GetLine$" = "" ^!DeleteLine
                    > ^!If "^$GetLine$" <> "" NEXT ELSE LOOP_TOP
                    > ^!Replace "\n+==========\n+" >> "\n==========\n" IWRSA
                    > ^!Jump DOC_END
                    > :LOOP_END
                    > ^!If "^$GetLine$" = "" ^!KeyBoard BACKSPACE
                    > ^!If "^$GetLine$" <> "" NEXT ELSE LOOP_END
                    > ^!InsertText ^%nl%
                    > ^!SetWordWrap ^%ww%
                    >
                    > Try it, let us know.
                    >
                    > ºvº
                    > 05.09.07
                    > hrs > hsavage@...

                    The regex can be shortened somewhat as follows,

                    ^!Replace "\n+{==========}\n+" >> "\n\1\n" IWRSA

                    ºvº
                    05.09.07
                    hrs > hsavage@...
                  • hsavage
                    ... Don, Here s my latest revision to remove extra blank lines and transform the files into bite-sized indexed/numbered files. Try it to see if it suits. The
                    Message 9 of 16 , Sep 10, 2005
                    • 0 Attachment
                      Don - htmlfixit.com wrote:
                      >>> if I have a variable that contains this
                      >
                      > blankline
                      > blankline
                      > text
                      > text
                      > blankline
                      > text
                      > text
                      > blankline
                      > blankline
                      > ==========
                      > blankline
                      > blankline
                      > blankline
                      > text
                      > text
                      > blankline
                      > text
                      > text
                      > ==========
                      > blankline
                      > blankline
                      > blankline
                      > text
                      > text
                      > blankline
                      > text
                      > text
                      > blankline
                      > blankline
                      > blankline
                      >
                      > The number of blank lines before or after the content is varied. So
                      > simple search and replaces don't work. I have already taken the file
                      > and stepped through it so that in step one, the first part before the
                      > first dividing line/delimiter is loaded into a variable. I then save
                      > that variable to a new file. Before saving, however, I want to clean it
                      > up. I may be able to do it with your clips which I will study after
                      > saving it. If I could do it before saving it, even better. In fact if
                      > I could do the file before running my steps on it, maybe that would
                      > work. I don't know the file size as this is to help another person.
                      > The sample they sent me was fairly small.
                      >
                      > Double returns between paragraphs aren't my concern, it was the extra
                      > white space before and after the delimiters that I am trying to get out
                      > of the variables.

                      Don,

                      Here's my latest revision to remove extra blank lines and transform the
                      files into bite-sized indexed/numbered files. Try it to see if it suits.

                      The blankline entries above represents an empty line. I did multiple
                      paste to create a sample file just over 60 kb, clip performed great.


                      H="X_Blanklines"
                      ^!Set %ww%=^$IsWordWrap$
                      ^!SetWordWrap 0
                      ^!SetScreenUpdate 0
                      ;
                      ; sets filename variable and tab location to use later
                      ^!Set %doc_idx%=^$GetDocIndex$
                      ^!Set %fn%=^$GetPath(^##)$^$GetName(^##)$
                      ;
                      ; removes empty lines from bof
                      ^!Jump 1
                      :LOOP_TOP
                      ^!If "^$GetLine$" = "" ^!DeleteLine
                      ^!If "^$GetLine$" <> "" NEXT ELSE LOOP_TOP
                      ;
                      ; removes empty lines either side of delimiters
                      ^!Replace "\n+{==========}\n+" >> "\n\1\n" IWRSA
                      ^!Jump DOC_END
                      ;
                      ; removes empty lines from eof
                      :LOOP_END
                      ^!If "^$GetLine$" = "" ^!KeyBoard BACKSPACE
                      ^!If "^$GetLine$" <> "" NEXT ELSE LOOP_END
                      ;
                      ; adds delimiter to eof and saves
                      ^!InsertText "^p==========^p"
                      ^!Save
                      ;
                      ; creates temp file to dissect
                      ^!Set %tf%=^$GetTempFile$
                      ^!TextToFile "^%tf%" ^$GetFileText(^##)$
                      ^!Open "^%tf%"
                      ^!SetWordWrap 0
                      ;
                      ; selects topmost text for numbered file - allows 3 digit numbers
                      ^!Set %df%=0
                      :DF
                      ^!Inc %df%
                      ^!Set %df%=^$StrCopyRight("00^%df%";3)$
                      ^!Find "==========" S
                      ^!IfError END
                      ^!DeleteLine
                      ^!SelectTo 1:1
                      ;
                      ; cuts and copies each selection numbered file
                      ^!Menu Edit/Cut
                      ^!TextToFile "^%fn%_^%df%." ^$GetClipboard$
                      ^!Goto DF
                      :END
                      ;
                      ; destroys empty tempfile after dissection, refocuses original file
                      ^!DestroyDoc
                      ^!SetDocIndex ^%doc_idx%
                      ;
                      ; removes previously added delimiter at eof and saves
                      ^!Jump DOC_END
                      ^!Find "==========" B
                      ^!IfError SKIP
                      ^!DeleteLine
                      ^!SetWordWrap ^%ww%
                      ^!Save

                      With the commented lines removed it's not a very large clip.

                      ºvº
                      05.09.10
                      hrs > hsavage@...
                    Your message has been successfully submitted and would be delivered to recipients shortly.