string llStringTrim( string src, integer type );
Forced delay: 0.0 seconds. Energy: 10.0.
Returns a string that is src with leading and/or trailing white space (spaces, tabs, and line feeds) trimmed from it.
| Constant | Description | |
|---|---|---|
| STRING_TRIM_HEAD | 0x1 | Trims white space off the beginning. |
| STRING_TRIM_TAIL | 0x2 | Trims white space off the end. |
| STRING_TRIM | 0x3 | Trims white space off the beginning and end. |
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 'white space' characters on a string that were removed (not particularly useful but shows how to use the function).
default
{
state_entry()
{
llListen(4, "", llGetOwner(), "");
}
on_rez(integer start_param)
{
llResetScript();
}
listen(integer channel, string name, key id, string message)
{
//track the length
integer length = llStringLength(message);
//trim message (not necessary to store these to variables but makes reading easier)
string trim_left = llStringTrim(message, STRING_TRIM_HEAD);
string trim_right = llStringTrim(message, STRING_TRIM_TAIL);
string trim_both = llStringTrim(message, 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_both + "\"");
}
}
while(llStringLength(s) != llStringLength(s = llReplaceSubString(s, " ", " ", 0)));
s = llStringTrim(s, STRING_TRIM);
llReplaceSubString("some words to remove the spaces from", " ", "", 0);
list l = [" a ", " b", "c ", " d "];
list trimmedList = llJson2List(llList2Json(JSON_ARRAY, l));
llDumpList2String(llParseString2List(src, [" "], []), " "); //works but can use a large quantity of memory//Added By To-mos Codewarrior
string str1 = "some words to remove the spaces from";
integer index;
while(~index=llSubStringIndex(str1," ")) {
data=llDeleteSubString(str1,index,index);
}(string)llParseString2List(src, [" "], []); //works but can use a large quantity of memoryDate of release 25-04-2007