Deleting Empty Lines From a Container |
|
However this breaks down when you have thousands of lines of text, since therepeat with x = (the number of lines of tData) down to 1 if line x of tData is empty then delete line x of tData end repeat
repeat with
construct gets slower and slower as the value of
x increases.
Those that are concerned with performance know that repeat for each
if a lot faster, but it requires additional lines of code, and it also effectively stores a
copy of your original container in memory, minus the blank lines:
However you can also do this with a simple one-liner, which shows the power of the Revolution scripting language:put "" into tNewData repeat for each line tLine in tData if tLine is not empty then put tLine & CR after tNewData end if end repeat delete char -1 of tData -- removes trailing CR
This not only removes the blank lines, but also works on the same variable, thus conserving memory.filter tData without empty
Enjoy!
Posted 3/1/2006 by Ken Ray