Deleting 1 line from a long list

xbury.cs at xbury.cs at
Tue Oct 21 05:20:37 EDT 2003


First you should use a reverse loop to avoid the error of deleting 
non-existing lines

repeat with x = totallines down to 1
  if pString is not in thislist then exit repeat

You can shorten it with this statement too...
put the number of lines in char 1 to offset(pstring,plist) into totallines

Using repeat with x = 1 to totallines will cause errors:
The totallines will not be exact after 1 deletion and you will repeat out 
of bounds...

The next fastest trick is to use lineoffset or offset to find those 
occurences. Repeat until the string
is no longer found. 

By far the fastest should be this though:
If you can predict what the line will be you can also use a replace ( 
thisstring & CR) with "" in mylist.
The other choice is to use the regular expression if your guess is not 
exact but grepable...

Xavier Bury
ext 6465

Igor Couto <igor at>
Sent by: use-revolution-bounces at
21/10/03 06:50
Please respond to How to use Revolution

        To:     use-revolution at
        cc:     ^
        Subject:        Deleting 1 line from a long list

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

use-revolution mailing list
use-revolution at

Visit us at

Internet communications are not secure and therefore Clearstream International does not accept legal responsibility for the contents of this message.

The information contained in this e-mail is confidential and may be legally privileged. It is intended solely for the addressee. If you are not the intended recipient, any disclosure, copying, distribution or any action taken or omitted to be taken in reliance on it, is prohibited and may be unlawful. Any views expressed in this e-mail are those of the individual sender, except where the sender specifically states them to be the views of Clearstream International or of any of its affiliates or subsidiaries.


More information about the Use-livecode mailing list