Jump to content

A couple of one-liner list functions.


Gistya Eusebio
 Share

You are about to reply to a thread that has been inactive for 3900 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

(1)

// To remove all instances of [test] from list:

while (~q = llListFindList(listy,[test])) listy = llDeleteSubList(listy,q,q);

// Proof of concpet:

integer test = 5;
list listy = [3,3,4,5,2,1,6,5,3,5,5,2,3,2,1,5,5,3,2,2,5,5,5,5,2,1,1,3,3,5];
integer q;
while (~q = llListFindList(listy,[test])) listy = llDeleteSubList(listy,q,q);
llSay(0, llList2CSV(listy));

// returns:  3, 3, 4, 2, 1, 6, 3, 2, 3, 2, 1, 3, 2, 2, 2, 1, 1, 3, 3

(2) corollary

// To replace all instances of [test] from list with [replacement]: 

while (~q = llListFindList(listy,[test])) listy = llListReplaceList(listy,replacement,q,q+llGetListLength(test)-1);

// Proof of concept: (using variable declarations still from example above)

listy = [3,3,4,5,2,1,6,5,3,5,5,2,3,2,1,5,5,3,2,2,5,5,5,5,2,1,1,3,3,5];
list replacement = ["The creatures became incredibly obsessed with cat food."];
while (~q = llListFindList(listy,[test])) listy = llListReplaceList(listy,replacement,q,q+llGetListLength(test)-1);
llSay(0, llList2CSV(listy));

// returns:  3, 3, 4, The creatures became incredibly obsessed with cat food., 2, 1, 6, The creatures became incredibly obsessed with cat food., 3, The creatures became incredibly obsessed with cat food., The creatures became incredibly obsessed with cat food., 2, 3, 2, 1, The creatures became incredibly obsessed with cat food., The creatures became incredibly obsessed with cat food., 3, 2, 2, The creatures became incredibly obsessed with cat food., The creatures became incredibly obsessed with cat food., The creatures became incredibly obsessed with cat food., The creatures became incredibly obsessed with cat food., 2, 1, 1, 3, 3, The creatures became incredibly obsessed with cat food.

=G=

  • Like 1
Link to comment
Share on other sites

  • 1 month later...

tried the corallary but had to change it a bit?

        integer test = 5;
        integer q;
        list listy = [3,3,4,5,2,1,6,5,3,5,5,2,3,2,1,5,5,3,2,2,5,5,5,5,2,1,1,3,3,5];
        list replacement = ["five gone."];
        while (~q = llListFindList(listy,[test]))  listy = llListReplaceList(listy,replacement,q,q) ;
        llSay(0, llList2CSV(listy));

 

 btw: ty for these...great work :)

Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 3900 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...