Auto-remove blank lines in a list field
Brad Allen
BradAllen at mac.com
Sun Apr 7 14:54:01 EDT 2002
There are several ways to delete blank lines.
Here's the most straightforward:
put the number of lines in myText into lineCount
repeat with i = lineCount down to 1
if line i of myText is empty then delete line i of myText
end repeat
Here's another way, probably faster for large amounts of text, but
isn't very elegant:
repeat until offset(return & return,myText) = 0
replace return & return with return in myText
end repeat
if line 1 of myText is empty then delete line 1 of myText
The most elegant way to do it is probably using the replaceText
command, which may be powerful enough to accomplish this task without
even using a repeat loop. This is an advanced command which makes use
of regular expression technology for text pattern matching. (Maybe
somebody on this list knows a regular expression to identify an
arbitrary number of consecutive blank lines...).
Whichever method you choose, you might consider enclosing your code
in a function, as in
function stripBlankLines inputText
<<code for stripping blank lines, put the cleaned up text into myVariable>>
return myVariable
end stripBlankLines
This will make it easily reusable throughout your project.
>Hello all,
>
>I have a list field and I am trying to write a script
>that upon "closeField" (or something appropriate),
>will automatically check each line in the field and
>remove/delete any blank lines in the list field; I
>have tried this a ton of different ways using
>variations of the repeat command, but have not been
>able to make it work.
>
>Thanks
>
>Steve
>
>__________________________________________________
>Do You Yahoo!?
>Yahoo! Tax Center - online filing with TurboTax
>http://taxes.yahoo.com/
>_______________________________________________
>use-revolution mailing list
>use-revolution at lists.runrev.com
>http://lists.runrev.com/mailman/listinfo/use-revolution
--
More information about the use-livecode
mailing list