1

我有一个字符串:

string cover = "withaname"

我想更改withanamewithnoname.

然后我想更改withnonamewithanamegoose.

在LSL中完成此任务的最佳方法是什么?

4

2 回答 2

2

如果你有一个特殊的字符来分隔你的数据,你可以使用 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"
于 2009-07-23T06:33:17.097 回答
0

再次,不确定你想要什么。 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);
        }
    }
}
于 2013-05-02T17:47:26.890 回答