LlParseString2List
| 首页 | 函数 | 事件 | 类型 | 操作符 | 常数 | Flow Control | Script Library | Categorized Library | Tutorials |
| 函数名 |
|---|
| Function: list llParseString2List( string src, list separators, list spacers ); |
| 参数:
• string src – source string • list separators – separators to be discarded • list spacers – spacers to be kept |
| 返回值:
返回一个被 src 分解成字符串列表的列表,丢弃分隔符,保留间隔符,丢弃生成的任何 null (空字符串)值。 |
| 注意事项 |
|---|
注意事项
如果您想要它们(例如,为了保持列表的顺序) ,可以使用 llparse/stringkeepnulls;
|
| 示例 |
|---|
示例一
default
{
state_entry()
{
// This will say:
// <A><crazy><fox><.><Saw><the><moon><.><.>
string my_string = "A crazy fox. Saw the moon..";
list my_list = llParseString2List(my_string,[" "],["."]);
llOwnerSay("<" + llDumpList2String(my_list,"><") + ">");
// This will say:
// <A><crazy><fox><.><><><Saw><the><moon><.><><.><>
my_list = llParseStringKeepNulls(my_string,[" "],["."]);
llOwnerSay("<" + llDumpList2String(my_list,"><") + ">");
}
}
虽然 lsl 不支持 list-in-lists,但是您可以通过连续调用来模拟 list-in-lists,或者您可以使用 json.this 示例中有些项目提供了额外的信息。
string shoppinglist = "macaroni::pepperoni::bread#wheat::sausage#italian::coffee::syrup::apple::ice cream#strawberry#chocolate#vanilla";
default
{
state_entry()
{
list items = llParseString2List(shoppinglist, ["::"], []);
integer i = 0;
integer j = llGetListLength(items);
for(;i < j; ++i)
{
list desc = llParseString2List(llList2String(items, i), ["#"], []);
if(llGetListLength(desc) > 1)
{
list types = llDeleteSubList(desc,0,0);
llOwnerSay("Item: "+ llList2String(desc, 0) + " Type: " + llList2CSV(llDeleteSubList(types,-2,-1) + llDumpList2String(llList2List(types,-2,-1), " & ")));
} else {
llOwnerSay("Item: "+ (string)desc);
}
}
}
}
|
| 相关函数 |
|---|
| llParseStringKeepNulls |
| 相关事件 |
|---|