Deleting 1 line from a long list
Igor Couto
igor at pixelmedia.com.au
Tue Oct 21 00:50:10 EDT 2003
Hi all!
I was wondering if the way that I'm going about a certain task is
actually the easiest/fastest way. The task is: I have a list
(return-delimited) of several hundred words. I need to delete ONE
specific word from the list.
Right now, I'm using a repeat loop, iterating through the list until I
find the string, then deleting it:
# PRE: pLIst should be a return-delimited list of strings. pString
should be the text of one of the items in pList.
# POST: pList is returned, minus the line that contains/is pString.
function fDeleteLine pList,pString
if pList is empty then return empty
if pString is empty then return pList
repeat with x = 1 to number of lines in pList
if line x of pList is pString then
delete line x of pList
exit repeat
end repeat
return pList
end fDeleteLine
I know that the "repeat with x" structure is supposed to be slower than
other forms of repeat, and I also seem to remember some experienced
users in this list recommending using arrays in some way to speed up
search and replace functions in lists.
So: is there a faster way to do this?
Many thanks for any hints!
Kindest regards,
--
Igor de Oliveira Couto
----------------------------------
----------------------------------
More information about the use-livecode
mailing list