llJoinList
|
Gaudeon Wu
Hermit
Join date: 5 May 2003
Posts: 142
|
06-16-2003 19:08
Suggested function. string llJoinList(list src, string seperator) This function would take a list, join all elements in the list using the seperator and return the resulting string. Ok.. Ok.. I know I can do it using LSL in fact here is the function but if the LSL implementation Linden Labs creates is faster then I think it is a worthy enough feature. BTW I haven't used this code in SL as of this post so there may be bugs, if I find any I will update my post. string JoinList(list src, string seperator) { integer i = 0; string retval = "";
for(i = 0; i < (llGetListLength(src) - 1); i++) { retval += llList2String(src,i) + seperator; }
retval += llList2String(src,(llGetListLength(src) - 1));
return retval; }
|
Huns Valen
Don't PM me here.
Join date: 3 May 2003
Posts: 2,749
|
06-17-2003 07:39
I use this one... string join(list j, string delim) { string s; integer i; integer end=(llGetListLength(j) - 1); for(i=0; i<=end; i++) { s+=llList2String(j,i); if(i<end) s+=delim; } return s; }
|
Gaudeon Wu
Hermit
Join date: 5 May 2003
Posts: 142
|
06-17-2003 10:24
Which is the same thing except you run an 'if' statement in your 'for' loop (that 'if' statement whether the condition is true or not runs every iteration of the loop), tsk tsk that's extra processing used up  I do this at times as well btw so no need to flame me here or in the future about my comment, just bantering Oh and I did test this my function and works fine, still would be nice if Linden Labs had optimized utility functions such as this.
|
Bob Brightwillow
Technologist
Join date: 7 Feb 2003
Posts: 110
|
06-17-2003 10:41
From a quick glance, it looks like you want a generalized llList2CSV. That's a good idea. Lindens?
|
Christopher Omega
Oxymoron
Join date: 28 Mar 2003
Posts: 1,828
|
06-17-2003 11:53
I would also like a better llList2CSV function. Just to add to the thread, Im gonna post a function that will turn a list2CSV in correct grammitical format (this code is untested but it *should* work). If you like no comma before an and: string MakeGrammitical(list src) { string last_index; integer indices = (llGetListLength(src) - 1) if(indicies != 0 && indices != -1) last_index = llList2String(src,indecies,indecies); else if(indicies == 0) return src; else return; list mod_src = llDeleteSubList(src,indicies,indicies); string edited = llList2CSV(mod_src) + " and " + last_index; return edited; }
eep, ran outta time, ill poist other version later
|
Bob Brightwillow
Technologist
Join date: 7 Feb 2003
Posts: 110
|
06-17-2003 13:40
I found it ironic that "MakeGrammatical" was spelled incorrectly ;) Here's untested code to form a list of items from a LSL list. string listToString(list in) { if (llGetListLength(in) == 0) return ""; if (llGetListLength(in) == 1) return llList2String(in, 0); if (llGetListLength(in) == 2) return llList2String(in, 0) + " and " + llList2String(in, 1); string out; integer i; for (i = 0; i < llGetListLength(in) - 1; i++) { out = out + llList2String(in, i) + ", "; } out = out + "and " + llList2String(in, llGetListLength(in) - 1); return out; }
(Of course, this produces a grammatically correct list of items. To discourage the prevalence of the American style list of items, I will not provide a function to create one.)
|
Bob Brightwillow
Technologist
Join date: 7 Feb 2003
Posts: 110
|
06-17-2003 13:45
Oh, and before any CS people boo at me for apparently extraneous recursion, consider that llList2CSV recurses over the elements anyway.
|
Jake Cellardoor
CHM builder
Join date: 27 Mar 2003
Posts: 528
|
06-17-2003 13:57
From: someone Originally posted by Bob Brightwillow llList2CSV recurses over the elements anyway. How can you tell?
|
Bob Brightwillow
Technologist
Join date: 7 Feb 2003
Posts: 110
|
06-17-2003 14:09
From: someone Originally posted by Jake Cellardoor How can you tell? How else would you do it? Somewhere, something is copying bytes out of the list and into the string.
|
Jake Cellardoor
CHM builder
Join date: 27 Mar 2003
Posts: 528
|
06-17-2003 16:04
From: someone Originally posted by Bob Brightwillow How else would you do it? Somewhere, something is copying bytes out of the list and into the string. When you said "recurse," did you mean "recursion," i.e. a function calling itself? The function you posted doesn't actually call itself, but I took your statement to mean that the implementation of llList2CSV called itself. It might call itself, or it might not; I believe any recursive algorithm can be replaced by an iterative one.
|
Christopher Omega
Oxymoron
Join date: 28 Mar 2003
Posts: 1,828
|
06-18-2003 12:32
From: someone Originally posted by Bob Brightwillow I found it ironic that "MakeGrammatical" was spelled incorrectly 
Here's untested code to form a list of items from a LSL list.
string listToString(list in) { if (llGetListLength(in) == 0) return ""; if (llGetListLength(in) == 1) return llList2String(in, 0); if (llGetListLength(in) == 2) return llList2String(in, 0) + " and " + llList2String(in, 1); string out; integer i; for (i = 0; i < llGetListLength(in) - 1; i++) { out = out + llList2String(in, i) + ", "; } out = out + "and " + llList2String(in, llGetListLength(in) - 1); return out; }
(Of course, this produces a grammatically correct list of items. To discourage the prevalence of the American style list of items, I will not provide a function to create one.) Yep, I really had to type my post into the forums quickly, the computer I was using at the time wasnt avalible for use for a long period of time... Since the code I posted was written using the syntax of LSL that I can remember, the post code did have some errors (was only able to test it last night). I corrected it, and will post the code here, if people want it... 'cause your code looks alot nicer then mine lol. And Im not sure what you mean by american style lists...
|
Bob Brightwillow
Technologist
Join date: 7 Feb 2003
Posts: 110
|
06-18-2003 15:14
From: someone Originally posted by Jake Cellardoor When you said "recurse," did you mean "recursion," i.e. a function calling itself? You're quite right, the correct term would have been to iterate. My mistake.
|
Gaudeon Wu
Hermit
Join date: 5 May 2003
Posts: 142
|
11-27-2003 23:42
bump 
|
Christopher Omega
Oxymoron
Join date: 28 Mar 2003
Posts: 1,828
|
11-28-2003 00:34
Dang... shouldnt have posted my own thread on this... I completely forgot it's been suggested before. I still like my naming of the function better  llParseList2String() rather then llJoinList().... makes it bit more eiasier to remember, since it's doing the reverse of llParseString2List(). EDIT: Here's a link to the post I made on it: llParseList2String()
|
Gaudeon Wu
Hermit
Join date: 5 May 2003
Posts: 142
|
11-28-2003 00:54
I agree llParseList2String shows a closer relationship to llParseString2List 
|