Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

message parsing

Mod Faulkner
Registered User
Join date: 11 Oct 2005
Posts: 187
01-17-2006 15:00
Other than parsing to list and back, is there a way to split string message into two part at a praticular character so that can they them be assigned to the appropriat variable type. The phrase contains a name and a vector locaton, both of unknown lenght. The one common denominator is the "< >" enclosing the vector.

Thanks, Mod
Ziggy Puff
Registered User
Join date: 15 Jul 2005
Posts: 1,143
01-17-2006 15:12
If you can use a special character as a divider that won't occur in the name, you could do it. Let's say you use the | character, so the string is namexyz|<vector>

CODE

integer barPos = llSubStringIndex(encryptedString, "|");
string name = llGetSubString(encryptedString, 0, barPos - 1);
vector position = (vector)llGetSubString(encryptedString, barPos + 1, -1);


Basically, find the position of the unique delimiter, then everything before that is one of your data items, and everything after that is the other data item. If the pattern is longer than 1 character, then you'll have to replace barPos + 1 with the strlen of the pattern string, to skip over the correct number of characters.
Damien Took
Meat Popsicle
Join date: 3 Dec 2004
Posts: 151
01-17-2006 15:15
Assuming the string is something like this: "Damien Took <128,128,75>"

CODE

integer pos;
string name;
vector location;

string input = "Damien Took <128,128,75>";

// First, we find the position of the vector
pos = llSubStringIndex(input, "<");
location = (vector)llGetSubString(input,pos,-1); // Gets your vector from the string
name = llGetSubString(input,0,pos-1); // Gets the name from the string


I am a bit slower :)
This is slightly different because it assumes that you have no delimeter and only one name and one vector in the string.
Mod Faulkner
Registered User
Join date: 11 Oct 2005
Posts: 187
Thanks
01-18-2006 02:53
Thanks Ziggy and Damien. Both methods worked perfectly, and you got me out of another fix.

Mod