LlStringTrim
De DigiWiki.
Whenever you are accepting unstructured input from a user -- whether via chat or via a notecard -- it is a good idea to always full trim it:
llStringTrim("User input", STRING_TRIM);
This example returns the number of leading and trailing spaces on a string (not particularly useful but shows how to use the function).
default { state_entry() { llListen(4, "", llGetOwner(), ""); } on_rez(integer a) { llResetScript(); } listen(integer chan, string name, key id, string msg) { //test for and remove wrapping single or double quotes if(~llSubStringIndex("'\"", llGetSubString(msg,0,0))) if(llGetSubString(msg,-1,-1) == llGetSubString(msg,0,0)) msg = llDeleteSubString(msg, -1, 0); //track the length integer length = llStringLength(msg); //trim msg (not necessary to store these to variables but makes reading easier) string trim_left = llStringTrim(msg, STRING_TRIM_HEAD); string trim_right = llStringTrim(msg, STRING_TRIM_TAIL); string trim = llStringTrim(msg, STRING_TRIM); //output the results llOwnerSay("Initial length = " + (string)length + "\nLeading Spaces = " + (string)(length - llStringLength(trim_left))+ "\nTrailing Spaces = " + (string)(length - llStringLength(trim_right))+ "\nTrimmed Message = \"" + trim + "\""); } }


