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

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

Expand Messages
  • Don - htmlfixit.com
    ... yes, always the same string of characters is used as the delimiter
    Message 1 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 2 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 3 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 4 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 5 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.