Don't click here unless you want to be banned.

LSL Wiki : llCSV2List

HomePage :: PageIndex :: RecentChanges :: RecentlyCommented :: UserSettings :: You are
list llCSV2List(string src)

Create a list from a string of comma separated values (CSV) specified in src.

All list items will be of type string, regardless of their contents (llGetListEntryType will always return TYPE_STRING). This should be kept in mind if you intend to sort such a list using llListSort or transmit it via llMessageLinked.

llList2CSV performs the inverse function.

One thing to be aware of is that llCSV2List has a built in escaping mechanism. Anything inside angle brackets (like <0, 5, 10>) remains unparsed no matter if it is a vector, rotation or just garbage.

Another thing to beware of is this function will return invalid results if a value in the CSV string contains quoted commas, which should be ignored but instead create false field divisions thus corrupting the data. This is quite a cretinous bug and renders this function useless for any serious purpose.

If you need more flexibility, such as separators other than comma, use llParseString2List instead.

Heres an example showing the difference between a list before and after using llCSV2List:

string list2stringtype(list input) { // converts list to a CSV string with type information prepended to each item
    list        output;
    string      s;
    integer     i;
    for (i = 0; i < llGetListLength(input); i++) {
        if (llGetListEntryType(input, i) == TYPE_INTEGER) s = "(integer)";
        else if (llGetListEntryType(input, i) == TYPE_FLOAT) s = "(float)";
        else if (llGetListEntryType(input, i) == TYPE_STRING) s = "(string)";
        else if (llGetListEntryType(input, i) == TYPE_KEY) s = "(key)";
        else if (llGetListEntryType(input, i) == TYPE_VECTOR) s = "(vector)";
        else if (llGetListEntryType(input, i) == TYPE_ROTATION) s = "(rotation)";
        else if (llGetListEntryType(input, i) == TYPE_INVALID) s = "(INVALID)";

        output += [s + llList2String(input, i)];
    return llList2CSV(output);

default {
    state_entry() {
        list        l;

        l = [4, 4.4f, "banana", "15.3", <1,2,3>, <4,5,6,7>]; // this list has proper type information
        llSay(0, list2stringtype(l));
        l = llCSV2List(llList2CSV(l));  // this list is converted to a CSV string and back
        llSay(0, list2stringtype(l));   // causing it to loose all type information

And here are two functions to safely transport lists through strings (as used in llMessageLinked) while retaining their type information:

string List2TypeCSV(list input) { // converts a list to a CSV string with type information prepended to each item
    integer     i;
    list        output;
    integer     len;

    len=llGetListLength(input); //this can shave seconds off long lists
    for (i = 0; i < len; i++) {
        output += [llGetListEntryType(input, i)] + llList2List(input, i, i);
    return llList2CSV(output);

list TypeCSV2List(string inputstring) { // converts a CSV string created with List2TypeCSV back to a list with the correct type information
    integer     i;
    list        input;
    list        output;
    integer     len;
    input = llCSV2List(inputstring);

    for (i = 0; i < len; i += 2) {
        if (llList2Integer(input, i) == TYPE_INTEGER) output += (integer)llList2String(input, i + 1);
        else if (llList2Integer(input, i) == TYPE_FLOAT) output += (float)llList2String(input, i + 1);
        else if (llList2Integer(input, i) == TYPE_STRING) output += llList2String(input, i + 1);
        else if (llList2Integer(input, i) == TYPE_KEY) output += (key)llList2String(input, i + 1);
        else if (llList2Integer(input, i) == TYPE_VECTOR) output += (vector)llList2String(input, i + 1);
        else if (llList2Integer(input, i) == TYPE_ROTATION) output += (rotation)llList2String(input, i + 1);
    return output;

default {
    state_entry() {
        list    l;
        string  s;
        l = [4, 4.4, "banana", "15.3", <1, 2, 3>, <4, 5, 6, 7>]; // a list with nice type information

        s = List2TypeCSV(l); // convert to CSV string with type information prepended to each item
        l = TypeCSV2List(s); // convert back to list with proper type information
        if (llGetListEntryType(l, 5) == TYPE_ROTATION) llSay(0, "Hooray!"); // it worked

A variation using the newer dump/parse methods can be found at ExampleListConversion.

This article wasn't helpful for you? Maybe the related article at the LSL Portal is able to bring enlightenment.

Functions | Lists | llList2CSV
Comments [Hide comments/form]
Hehe, with the typeCSV2List() function, you used the llList2*() functions specific to each type. Since everything in the list is a string, some of these llList2*() functions dont work properly (espicially the llList2Vector() and llList2Rotation() functions). Its best to first extract the value from the list as a string (llList2String()) and then explicitly typecast it to the type you want. :)
-- ChristopherOmega (2004-01-15 21:56:11)
Attach a comment to this page: