empty lines in field
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
-
- Posts: 73
- Joined: Sat Apr 08, 2006 6:51 pm
empty lines in field
When a field is sorted the empty lines are at the top. How can I delete these empty lines?
In nova fert animus mutatas dicere formas corpora.
Re: empty lines in field
Hi Preston
Try this :
All the best
Jean-Marc
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
Jean-Marc
https://alternatic.ch
Re: empty lines in field
Hi Preston,
Another somewhat cruder way of deleting empty lines from the top of the field would be:
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:
Regards,
Michael
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
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
Michael
Re: empty lines in field
Hi all,
the fastest way is and will always be a "repeat for each...." loop!
This insanely fast, even with >10000 lines!
Best
Klaus
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
...

Best
Klaus
Re: empty lines in field
Why not use
Code: Select all
filter fld "myField" without EMPTY
Re: empty lines in field
https://alternatic.ch