Elisabeth Ohmai Posted December 22, 2022 Share Posted December 22, 2022 Hi! What is the simplest way to detect is the word last at the string or not? Link to comment Share on other sites More sharing options...
Elisabeth Ohmai Posted December 22, 2022 Author Share Posted December 22, 2022 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 More sharing options...
panterapolnocy Posted December 22, 2022 Share Posted December 22, 2022 (edited) 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 December 22, 2022 by panterapolnocy Link to comment Share on other sites More sharing options...
Elisabeth Ohmai Posted December 22, 2022 Author Share Posted December 22, 2022 Oh, nice! Thanks! Link to comment Share on other sites More sharing options...
Marvin Benelli Posted December 23, 2022 Share Posted December 23, 2022 (edited) Oops, deleted because same solution Edited December 23, 2022 by Marvin Benelli Link to comment Share on other sites More sharing options...
Recommended Posts
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