Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Parsing Strings?

Floog Stuart
Registered User
Join date: 28 Jun 2006
Posts: 12
10-23-2006 19:11
Okay, I'm working on a thing that copies what you say using prims. I want to know how to parse the string message down to the 1st letter, then just the 2nd letter, then the 3rd. etc,etc. I'm not sure how I would do this, any help?
DoteDote Edison
Thinks Too Much
Join date: 6 Jun 2004
Posts: 790
10-23-2006 19:28
The lslwiki.com is scripter's best friend...

Use llGetSubString(). That function takes a string and returns the specified section of it. The wiki explains it well, but basically you'll do something like:

integer x = 6; // position in the string to check, starting at zero
string sentence = "Hello Avatar!"; // the string to scan
string letter = llGetSubString(sentence, x, x);

letter will become "A", the 6th position within the string.
Osgeld Barmy
Registered User
Join date: 22 Mar 2005
Posts: 3,336
10-23-2006 19:38
if you can afford to use a list ...
CODE

list data;
default
{
state_entry()
{
llListen(27,"",llGetOwner(),"");
}

listen(integer channel, string name, key id, string message)
{
integer total = llStringLength(message);
integer x;
while (x < total)
{
data += llGetSubString(message,x,x);
++x;
}

llOwnerSay(llDumpList2String(data,"^"));
}
}


just dont forget to clean out the list once your done using the data (data = []; )
Eloise Pasteur
Curious Individual
Join date: 14 Jul 2004
Posts: 1,952
10-24-2006 02:26
Whilst Osgeld's approach will work, and is possibly the best bet for things of random length (parsing sentences into words say, although you can nibble that with the string functions too depending on what you want to do with it) I'd go with the llGetSubString() approach.

I *like* lists. I use them probably more often than needed. For that specific application, I'd still use llGetSubString(). It is, however, good to know about llParseString2List as well, there are times when nothing else will do.
_____________________
Eloise's MiniMall
Visit Eloise's Minimall
New, smaller footprint, same great materials.

Check out the new blog