Jump to content

Last word at the string


Elisabeth Ohmai
 Share

You are about to reply to a thread that has been inactive for 166 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

I used this

default
{
    touch_end(integer num){
        string str = "This is the test string";
        string word = "string";
        integer index = llSubStringIndex(str, word);
        if(~index){ // found
            integer lenght = llStringLength(word);
            string symbol = llGetSubString(str, index+lenght+1, index+lenght+1);
            if(symbol == "") llOwnerSay("The word is last");
            else llOwnerSay("The word isn't last");
        }
    }
}

 

Link to comment
Share on other sites

default
{
    touch_end(integer num)
    {

        string str = "This is the test string";
        string word = "string";

        // Uncomment if you want case-insensitive comparison
        // word = llToLower(word);
        // str = llToLower(str);

        // If you want to detect if string is at the end, regardless of spaces
        // Will say that "abcstring" in str is last

        if (llGetSubString(str, -llStringLength(word), -1) == word) {
            llOwnerSay("The word is last (substring)");
        } else {
            llOwnerSay("The word isn't last (substring)");
        }

        // If you know that words are divided by spaces
        // Will say that "abcstring" in str is not last

        if (llList2String(llParseString2List(str, [" "], []), -1) == word) {
            llOwnerSay("The word is last (list)");
        } else {
            llOwnerSay("The word isn't last (list)");
        }

    }
}

 

Edited by panterapolnocy
Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 166 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...