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, 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 1 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.