// Separate_Words , by Ppaatt Lynagh , from http://wiki.secondlife.com/wiki/Separate_Words // Keep the spacers, discard the separators, and get the words in between, within // astonishing limits described at http://wiki.secondlife.com/wiki/llParseString2List list keepSpacersDiscardSeparators(list sources, list separators, list spacers) { list words = []; integer index; integer sourcing = llGetListLength(sources); for (index = 0; index < sourcing; ++index) { string source = llList2String(sources, index); words += llParseString2List(source, separators, spacers); } return words; } // Keep the spacers and get the words in between. list keepSpacers(list sources, list spacers) { list words = sources; integer index; integer spacing = llGetListLength(spacers); for (index = 0; index < spacing; index += 8) { list someSpacers = llList2List(spacers, index, index + 8 - 1); words = keepSpacersDiscardSeparators(words, [], someSpacers); } return words; } // Discard the separators but get the words in between. list discardSeparators(list sources, list separators) { list words = sources; integer index; integer separating = llGetListLength(separators); for (index = 0; index < separating; index += 8) { list someSeparators = llList2List(separators, index, index + 8 - 1); words = keepSpacersDiscardSeparators(words, someSeparators, []); } return words; } // Keep the spacers and discard the separators and get the words in between. list separateWords(string src, list separators, list spacers) { return discardSeparators(keepSpacers([src], spacers), separators); } // Demo keeping the spacers, discarding the separators, and getting the words in between. string src() { return "42 0.99 \"00000000-0000-0000-0000-000000000000\"" + " [abc, def] \"xyz\\\\\"zyx ijk\" <0, 1, 2, 3> // source literals"; } string LF = "\n"; string DQUOTE = "\""; // double quote string ESCAPE = "\\"; list spacers = [DQUOTE, "(", ")", "<", ">", "[", "]", "/", "+", "-", "*", "%", ESCAPE]; list separators() { string TAB = llUnescapeURL("%09"); // != "\t" string CR = llUnescapeURL("%0D"); // != "\r" return [TAB, LF, CR, " ", ",", ";"]; } ownerSayStrings(list strings) { integer stringing = llGetListLength(strings); integer index; for (index = 0; index < stringing; ++index) { llOwnerSay((string) index + ": " + llList2String(strings, index)); } } default { state_entry() { list words = separateWords(src(), separators(), spacers); ownerSayStrings(words); llOwnerSay(src()); llOwnerSay("OK"); } }