Page 1 of 1

empty lines in field

Posted: Fri Nov 12, 2010 2:36 pm
by Preston Shea
When a field is sorted the empty lines are at the top. How can I delete these empty lines?

Re: empty lines in field

Posted: Fri Nov 12, 2010 3:02 pm
by jmburnod
Hi Preston
Try this :

Code: Select all

on DoNoLineEmptyInFld 
   put "myField" into LeCurFld
   put NoLineEmpty(LeCurFld) into fld LeCurFld
end DoNoLineEmptyInFld

function NoLineEmpty pFld
   put fld pFld into rNoLineEmpty
   put the num of lines of rNoLineEmpty into nbl
   repeat with i = nbl down to 1
      if line i of rNoLineEmpty = empty then
         delete line i  of rNoLineEmpty
         wait 2 milliseconds 
      end if
   end repeat
   return rNoLineEmpty
end NoLineEmpty
All the best

Jean-Marc

Re: empty lines in field

Posted: Fri Nov 12, 2010 4:37 pm
by Regulae
Hi Preston,

Another somewhat cruder way of deleting empty lines from the top of the field would be:

Code: Select all

on mouseUp
   repeat for 100
      if line 1 of fld "myField" is empty then
         delete line 1 of fld "myField"
      else 
         exit repeat
      end if
   end repeat
end mouseUp
This will delete up to 100 blank lines at the start of a field. You could of course increase the number, as it exits once it arrives at the first non-empty line. I mention it as a matter of interest, and also as a way of highlighting the advantages of Jean-Marc’s approach. It is more general than mine, because it will delete all blank lines occurring anywhere in a field (having first, for speed, put the contents of the field into the variable rNoLineEmpty). Note also how it counts down from the total number of lines in the field- this is important when you are deleting lines, as when you delete a line, all the lines which follow the deleted line are renumbered. Jean-Marc’s NoLineEmpty function is thus a handy general-purpose tool.
Edit: Another method which only removes blank lines at the top of a field is:

Code: Select all

on mouseUp
   put word 1 of fld "myField" into firstWord
   delete line 1 to (lineOffset(firstWord,fld "myField") - 1) in fld "myField"
end mouseUp
Regards,

Michael

Re: empty lines in field

Posted: Fri Nov 12, 2010 6:57 pm
by Klaus
Hi all,

the fastest way is and will always be a "repeat for each...." loop!

Code: Select all

...
put fld "with empty lines" into tField
lock screen
repeat for each line tLine in tField

  ## "repeat for each..." is READ only, so we cannot modify the content of tLine!
  ## But creating a new text variable will do
  if tLine <> empty then
    put tLine & CR after tNew
  end if
end repeat
delete char -1 of tNew
put tNew into fld "with empty lines"
unlock screen
...
This insanely fast, even with >10000 lines! :D


Best

Klaus

Re: empty lines in field

Posted: Sun Nov 14, 2010 7:33 am
by shaosean
Why not use

Code: Select all

filter fld "myField" without EMPTY

Re: empty lines in field

Posted: Sun Nov 14, 2010 10:31 am
by jmburnod
zwietzkstx ! ! :o

Code: Select all

filter fld "myField" without EMPTY
work fine for me

Best

Jean-Marc