Difference between revisions of "LlStringTrim"

From Second Life Wiki
Jump to: navigation, search
(llStringTrim trims all white-space, not just spaces)
m
Line 29: Line 29:
 
{{!}}Trims spaces off the beginning and end.
 
{{!}}Trims spaces off the beginning and end.
 
{{!}}}
 
{{!}}}
|examples
+
|examples=<pre>
 +
integer channel;                        // will be set by notecard
 +
string NOTECARD_NAME = "configuration";  // name of notecard goes here
 +
 
 +
key KQuery;                  // to seperate Dataserver requests
 +
 
 +
// UPDATES
 +
integer line;
 +
 
 +
default
 +
{
 +
    changed(integer change)       
 +
    {
 +
        // We want to reload channel notecard if it changed
 +
        if (change & CHANGED_INVENTORY)
 +
        {
 +
        llResetScript();
 +
        }
 +
       
 +
    }
 +
    state_entry()
 +
    {
 +
        KQuery = llGetNotecardLine(NOTECARD_NAME, line);// request line
 +
        line++ ;
 +
    }
 +
   
 +
    dataserver(key query_id, string data) {
 +
        if (query_id == KQuery) {
 +
            if (data != EOF) {    // not at the end of the notecard
 +
                // yay!  Parsing time
 +
                // first, is it a comment? or an empty line?
 +
                if (llGetSubString (data, 0, 0) != "#" && llStringLength (data) > 0)
 +
                {
 +
                    list parsed = llParseString2List (data, ["="], [""]) ;
 +
                    string token = llToLower (llStringTrim (llList2String (parsed, 0), STRING_TRIM)) ;
 +
                    if (token == "command_channel")
 +
                        channel = (integer)llStringTrim (llList2String (parsed, 1), STRING_TRIM) ;
 +
                }
 +
 
 +
                KQuery = llGetNotecardLine(NOTECARD_NAME, line);
 +
                line++;
 +
            } else {
 +
                llOwnerSay ("Done Reading Notecard: " + (string)NOTECARD_NAME) ;
 +
state configuration ;
 +
            }
 +
        }
 +
    } 
 +
 
 +
}
 +
 
 +
state configuration
 +
{
 +
 +
            state_entry()
 +
            {
 +
            llListen(channel, "", "", "");
 +
            llShout(0, "Channel set to " + (string)channel);
 +
            } 
 +
}
 +
</pre>
 +
Submitted by [https://wiki.secondlife.com/wiki/User:Revolution_Perenti Revolution Perenti]
 
|helpers
 
|helpers
 
|also_functions
 
|also_functions

Revision as of 10:33, 1 September 2007

Summary

Function: string llStringTrim( string src, integer type );

Returns a string that is src with leading and/or trailing white space (spaces, tabs, and line feeds) trimmed from it.

• string src
• integer type STRING_TRIM* flag(s)
Constant Description
STRING_TRIM_HEAD 0x01 Trims spaces off the beginning.
STRING_TRIM_TAIL 0x02 Trims spaces off the end
STRING_TRIM 0x03 Trims spaces off the beginning and end.

Examples

integer channel;                        // will be set by notecard
string NOTECARD_NAME = "configuration";  // name of notecard goes here

key KQuery;                   // to seperate Dataserver requests

// UPDATES
integer line;

default
{
    changed(integer change)         
    {
        // We want to reload channel notecard if it changed
        if (change & CHANGED_INVENTORY)
        {
        llResetScript();
        }
         
    }
    state_entry()
    {
        KQuery = llGetNotecardLine(NOTECARD_NAME, line);// request line
        line++ ;
    }
    
    dataserver(key query_id, string data) {
        if (query_id == KQuery) {
            if (data != EOF) {    // not at the end of the notecard
                // yay!  Parsing time
                // first, is it a comment? or an empty line?
                if (llGetSubString (data, 0, 0) != "#" && llStringLength (data) > 0)
                {
                    list parsed = llParseString2List (data, ["="], [""]) ;
                    string token = llToLower (llStringTrim (llList2String (parsed, 0), STRING_TRIM)) ;
                    if (token == "command_channel")
                        channel = (integer)llStringTrim (llList2String (parsed, 1), STRING_TRIM) ;
                }

                KQuery = llGetNotecardLine(NOTECARD_NAME, line);
                line++;
            } else {
                llOwnerSay ("Done Reading Notecard: " + (string)NOTECARD_NAME) ;
state configuration ;
            }
        }
    }  

}

state configuration
{
 
            state_entry()
            {
            llListen(channel, "", "", "");
            llShout(0, "Channel set to " + (string)channel);
            }   
}
Submitted by Revolution Perenti

Notes

This function is available in 1.13.4 onwards...

The following examples will make the same result.

string src = "   Dah    ";
st = llStringTrim(src, STRING_TRIM_HEAD);
st = llStringTrim(st , STRING_TRIM_TAIL);
string src = "   Dah    ";
st = llStringTrim(src, STRING_TRIM);

This is because (STRING_TRIM_HEAD | STRING_TRIM_TAIL) == STRING_TRIM.

Deep Notes

Search JIRA for related Issues

Signature

function string llStringTrim( string src, integer type );