我有一个字符串:
string cover = "withaname"
我想更改withaname
为withnoname
.
然后我想更改withnoname
为withanamegoose
.
在LSL中完成此任务的最佳方法是什么?
我有一个字符串:
string cover = "withaname"
我想更改withaname
为withnoname
.
然后我想更改withnoname
为withanamegoose
.
在LSL中完成此任务的最佳方法是什么?
如果你有一个特殊的字符来分隔你的数据,你可以使用 llList2String 之类的函数。
llGetSubString可能是您真正想要的。我真的不明白你的确切问题。
string The_String = "withaname";
integer i = llSubStringIndex(The_String, "a");
The_String = llInsertString(llDeleteSubString(The_String, i, i), i, "no");
llSay(0, The_String);
// says "withnoname"
再次,不确定你想要什么。 http://wiki.secondlife.com/wiki/Category:LSL_String#Useful_Functions
一些示例代码(抱歉,Google Prettify 没有突出显示 LSL):
default
{
touch_start(integer num_detected)
{
string myString = "this is some text";
// if you simply want to change the value
myString = "now diff"+"erent "+"text";
llSay(PUBLIC_CHANNEL, myString);
// if you want to change the value only if substring in string
if (llSubStringIndex(myString, "text") != -1)
{
myString = "string contained text as substring";
llSay(PUBLIC_CHANNEL, myString);
}
// if you want to replace a word in a sentence
// and you know the spelling and it's surrounded by spaces
list words = llParseString2List(myString, [" "], []);
integer found = llListFindList(words, ["text"]);
if (found != -1)// or use: if (~found)
{
words = llListReplaceList(words, ["textReplacedWithAnotherWord"], found, found);
myString = llDumpList2String(words, " ");
llSay(PUBLIC_CHANNEL, myString);
}
}
}