1

I have a string:

string cover = "withaname"

I would like to change the withaname to withnoname.

I would then like to change withnoname to withanamegoose.

What is the best way to accomplish this in LSL?

Ry-
  • 218,210
  • 55
  • 464
  • 476
  • 2
    what environment are you using (programming language, tools)? – Thilo Jul 22 '09 at 09:59
  • I assume that English is not your first language. Did you use Google Translate or something to create this question? It might actually be easier to understand if you posted it in your own language - you never know, there might be other people on SO who can understand it. I certainly can't understand the translated version. – Gary McGill Jul 22 '09 at 10:02
  • Can you tell us which language you are using and, a little bit of an understandable explanation of your problem? – Kirtan Jul 22 '09 at 10:02
  • @Gary: Even if he had posted it in his own language, we could have translated it to English using Google Translate. And, I don't think its translated by Google. – Kirtan Jul 22 '09 at 10:03
  • 2
    excuse me for my worse english. i thought you may understand my question –  Jul 22 '09 at 10:04
  • What programming language are you using? – Lloyd Powell Jul 22 '09 at 10:07
  • @Wandolf: no need to apologise - you have as much right to post questions here as everyone else. Still, I do think it might help you express yourself more clearly if you use your own language. – Gary McGill Jul 22 '09 at 10:09
  • @Wandolf: Stell die Frage auf deutsch, ich übersetze sie dann. Wichtig ist auf jeden Fall, welche Programmiersprache du benutzt. – balpha Jul 22 '09 at 11:23
  • Is that "lsl" as in "Linden Scripting Language"? – balpha Jul 22 '09 at 11:44
  • 6
    Es ist linden script Language. und es geht um die string cover = "withaname" und ich würde gerne "withaname" beliebig ersetzen. sollte die die schreibweise "inanführungszeichen" haben. nun wie mache ich dieses man besten? über eine linkend message z.b soll ich eine liste machen ist dieses immer noch ein string? wie sage ich es ihr man besten? if and else würde zu lang werden. und ich würde gerne cover behalten die dann "irgendwieinanführungzeichen" heißt. ich habe hier schon überall gesucht aber keine richtige hilfestellung für mein beginner problem gefunden. –  Jul 22 '09 at 18:21
  • 2
    Das kann man auch besser formulieren – Henrik P. Hessel Nov 10 '10 at 13:59

2 Answers2

2

If you have a special character that will separate your data, you can use functions such as llList2String.

llGetSubString Is probably what you are actually looking for. I really dont understand your exact question though.

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"
NULL
  • 109
  • 3
  • is there another way without replace or add? to change the complete withaname, not with llInsertString. can i go and use The_String? it would be better if i get the name "inanführungszeichen" ,may from another event. i need an answer in common for this. thanks –  Jul 23 '09 at 08:07
  • OK if I am understanding you, then your are just asking how to replace a variables value. string name = "aaaaa"; //name is aaaaa name = "bbbbb"; //name is bbbbb llSay(0, name); //Will say "bbbbb" However I find it hard to believe that you are really asking how to set the value of a string. So if not, I am sorry that this is not helpful. I really would like to help you, but I honestly do not understand what you are asking. – NULL Jul 23 '09 at 23:56
0

Again, not sure what you want. http://wiki.secondlife.com/wiki/Category:LSL_String#Useful_Functions

Some example code (sorry, Google Prettify doesn't highlight 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);
        }
    }
}
Jack
  • 1