Deleting 1 line from a long list

Jan Schenkel janschenkel at yahoo.com
Tue Oct 21 05:11:40 EDT 2003


--- Igor Couto <igor at pixelmedia.com.au> wrote:
> 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
> 

Hi Igor,

Try the following :

function fDeleteLine pList,pString
  if pList is empty then return empty
  if pString is empty then return pList
  set the wholeMatches to true
  put lineOffset(pString, pList) into tOffset
  return line 1 to (tOffset - 1) of pList & \
     return & line (tOffset + 1) to -1 of pList
end fDeleteLine

No testing occured while writing this email *grin* so
I'm not sure if it will be faster.

Hope this helped nonetheless,

Jan Schenkel.

=====
"As we grow older, we grow both wiser and more foolish at the same time."  (La Rochefoucauld)

__________________________________
Do you Yahoo!?
The New Yahoo! Shopping - with improved product search
http://shopping.yahoo.com


More information about the use-livecode mailing list