String Manipulation
|
Zena Juran
Registered User
Join date: 21 Jul 2007
Posts: 473
|
08-09-2009 17:00
HIyas Everyone, I would like to read the names of multiple notecards in an object and translate those names into llDialogue menu button strings. The notecard names will always have a substring of "Vol. #" in it as in "Oppenheimer Vol. 1". I would like to remove "Vol." so I am left with "Oppenheimer 1" (keeping the space). And then start removing letters at the end of "Oppenheimer" until somehow I can reach the max. character length of 10 and somehow insert a period ("."  for a result of something like "Oppenhe. 1". The notecard name will always very in length and sometimes not need to be shorten. I can get part of this but I need help trying to figure out the rest. Here is what I have so far.
while (n-- > 0) { string item = llGetInventoryName(INVENTORY_NOTECARD, n); string notecard1 = (string)llParseString2List(item, ["Vol."], []); if (llStringLength(notecard1) > 10) {
// This section is pretty much what I need to figure out
string notecard2 = ?; MENU_CARDS += [notecard2];
} else { MENU_CARDS += [notecard1]; } }
I haven't seen any examples in the LSL Portal or on here. All help will be greatly appreciated. Thanx 
|
Zena Juran
Registered User
Join date: 21 Jul 2007
Posts: 473
|
08-09-2009 18:20
I was thinking maybe something like this would work on shortening the length down:
while (llStringLength(notecard1) > 10) { integer x = (llStringLength(notecard1); notecard2 = llDeleteSubString(notecard1, x-3, x-3); notecard1 = notecard2; }
|
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
|
08-09-2009 18:30
default { state_entry() { string test = "Oppenheimer 1"; test = llDeleteSubString(test, 5, -3); llOwnerSay(test); } }
returns: temp3: Oppen 1 Other then that, since you are not using a set pattern for notecard names, I would highly suggest just coming up with a naming convention for the cards that does not exceed 12 characters.
_____________________
I (who is a she not a he) reserve the right to exercise selective comprehension of the OP's question at anytime. From: someone I am still around, just no longer here. See you across the aisle. Hope LL burns in hell for archiving this forum
|
Zena Juran
Registered User
Join date: 21 Jul 2007
Posts: 473
|
08-09-2009 18:53
This seems to compile. I have to wait until I do some other things before I can test it out. I'm using 10 as the max. character length... is it 12? 
while (n-- > 0) { item = llGetInventoryName(INVENTORY_NOTECARD, n); notecard1 = (string)llParseString2List(item, ["Vol."], []); if (llStringLength(notecard1) > 10) { x = llStringLength(notecard1); while(llStringLength(notecard1) > 9) { notecard2 = llDeleteSubString(notecard1, x-3, x-3); notecard1 = notecard2; } notecard1 = llInsertString(notecard1,7,"."); MENU_CARDS += [notecard1]; } else { MENU_CARDS += [notecard1]; } }
|
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
|
08-09-2009 19:02
From: Zena Juran This seems to compile. I have to wait until I do some other things before I can test it out. I'm using 10 as the max. character length... is it 12?  I was wrong it is not 12 and you will be lucky if you can get 10. It depends on the width of the characters; W is wider then an I for example. I just did a random test and it is more in the range of 8 or 9 characters.
_____________________
I (who is a she not a he) reserve the right to exercise selective comprehension of the OP's question at anytime. From: someone I am still around, just no longer here. See you across the aisle. Hope LL burns in hell for archiving this forum
|
Zena Juran
Registered User
Join date: 21 Jul 2007
Posts: 473
|
08-09-2009 19:05
From: Zena Juran This seems to compile. I have to wait until I do some other things before I can test it out. I'm using 10 as the max. character length... is it 12? 
while (n-- > 0) { item = llGetInventoryName(INVENTORY_NOTECARD, n); notecard1 = (string)llParseString2List(item, ["Vol."], []); if (llStringLength(notecard1) > 10) { x = llStringLength(notecard1); while(llStringLength(notecard1) > 9) { notecard2 = llDeleteSubString(notecard1, x-3, x-3); notecard1 = notecard2; } notecard1 = llInsertString(notecard1,7,"."); MENU_CARDS += [notecard1]; } else { MENU_CARDS += [notecard1]; } }
oops.. had to throw integer x into the while loop:
while (n-- > 0) { item = llGetInventoryName(INVENTORY_NOTECARD, n); notecard1 = (string)llParseString2List(item, ["Vol."], []); if (llStringLength(notecard1) > 10) { while(llStringLength(notecard1) > 9) { x = llStringLength(notecard1); notecard2 = llDeleteSubString(notecard1, x-3, x-3); notecard1 = notecard2; }
notecard1 = llInsertString(notecard1,7,"."); MENU_CARDS += [notecard1]; } else { MENU_CARDS += [notecard1]; } }
|
Zena Juran
Registered User
Join date: 21 Jul 2007
Posts: 473
|
08-09-2009 19:06
From: Jesse Barnett I was wrong it is not 12 and you will be lucky if you can get 10. It depends on the width of the characters; W is wider then an I for example. I just did a random test and it is more in the range of 8 or 9 characters. Well that throws everything off doesn't it... lol 
|
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
|
08-09-2009 20:59
From: Zena Juran Well that throws everything off doesn't it... lol  it gets worse.... it's also controlled by UI size.... I've gotten averages of up to 15-16 using a larger UI.... but very few do.... 9-10 is a good safety margin.
_____________________
| | . "Cat-Like Typing Detected" | . This post may contain errors in logic, spelling, and | . grammar known to the SL populace to cause confusion | | - Please Use PHP tags when posting scripts/code, Thanks. | - Can't See PHP or URL Tags Correctly? Check Out This Link... | - 
|
Beverly Ultsch
Registered User
Join date: 6 Sep 2007
Posts: 229
|
08-10-2009 05:15
Going back to the string manipulation for a moment, something along these lines should do it. string truncate(string input) { list temp = llParseString2List(input, [" Vol."], []); string second = llList2String(temp, 1); return llGetSubString(llList2String(temp, 0), 0, 10 - (llStringLength(second) + 2)) + ". " + second; }
default { state_entry() { llOwnerSay(truncate("Oppenheimer Vol.1")); } }
|
Zena Juran
Registered User
Join date: 21 Jul 2007
Posts: 473
|
08-10-2009 12:27
From: Beverly Ultsch Going back to the string manipulation for a moment, something along these lines should do it. string truncate(string input) { list temp = llParseString2List(input, [" Vol."], []); string second = llList2String(temp, 1); return llGetSubString(llList2String(temp, 0), 0, 10 - (llStringLength(second) + 2)) + ". " + second; }
default { state_entry() { llOwnerSay(truncate("Oppenheimer Vol.1")); } }
Very nice! If I understand this correctly, then the brackets around "Vol." will be parsed as the second element in list temp and not discarded as a separator? I'm on the verge of "grasping" lists in SL but not quite there yet. I avoided them for so long... lol 
|