The script will get a random line, which I then need to parse into a list. Now, most of the elements in the lines I will have will be seperated by a single char, more than likely the asterisk '*'.
However there may be times when I want to use the asterisk inside an element and thus use a different character to seperate the elements.
For this reason I created the following function, which will take the first character of the line and use it to seperate the rest of the line.
CODE
list ufParseString (string strSource)
{
string strSeperator = llGetSubString(strSource, 0, 0);
strSource = llDeleteSubString(strSource, 0, 0);
return llParseString2List(strSource, [strSeperator], []);
}
Now, this works fine for me. But I got to thinking, "this is a usefull function. why not make it available for everyone?". The only problem is some people may want to use more than one character to seperate their elements.
So I decided to remake it so that if the first character is a number (0-9) it would discard it and use the next set of characters as the seperator. The number of characters would be indicated by that first number. And here is what I have:
CODE
list ufParseString (string strSource)
{
string strSeperator = llGetSubString(strSource, 0, 0);
if (llSubStringIndex("0123456789", strSeperator) != -1)
{
strSeperator = llGetSubString(strSource, 1, (integer)strSeperator);
strSource = llDeleteSubString(strSource, 0, (integer)strSeperator);
return llParseString2List(strSource, [strSeperator], []);
}
strSource = llDeleteSubString(strSource, 0, 0);
return llParseString2List(strSource, [strSeperator], []);
}
It's not the best idea, I am sure, but it's what I came up with. But then I thought about Quotation marks. What if someone wanted to surround the elements with quotations. What about adding this to it?
CODE
if (strSeperator == "\"")
{
list lstSeperator = ["\"\"", "\" \"", "\",\"", "\", \"", "\" ,\"", "\" , \""];
}
Now it's getting confusing.
So, here is my question, I'll use the first one for what I want. Does the other sound like something people might want made available?
Is it simple enough that most should be able to figgure it out on their own?
Is there a better way to make a function that would allow people to define how the line is to be seperated at the beginning of the line?
Could something like this be added to or used to spruce up List Conversion or Safe List Conversion?
