Difference between revisions of "Left"

From Second Life Wiki
Jump to navigation Jump to search
m (<lsl> tag to <source>)
 
(4 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{{LSL Header}} __NOTOC__
{{LSL_Function
<div id="box">
|mode=user
== Function: [[string]] left([[string]] {{LSL Param|src}}, [[string]] {{LSL Param|divider}}); ==
|func=left
<div style="padding: 0.5em;">
|p1_type=string|p1_name=src
Returns text left of a specified separator
|p2_type=string|p2_name=divider
|return_type=string
|return_text=that is the text in '''src''' that is left of the first occurrence of '''divider'''.  
|func_desc=Returns text left of a specified separator
|func_footnote=
If '''divider''' is not found then '''src''' is returned in it's entirety.


See also: [[Right]]
See also: [[Right]]
 
|examples=
Example:<br />
<source lang="lsl2">string value = left("Colour=Brown", "="); //value == "Colour"</source>
 
|spec=<source lang="lsl2">string left(string src, string divider) {
string notecardparameter = left(sdata,"=");
    integer index = llSubStringIndex( src, divider );
//in a notecard line that reads Colour=Brown, returns "Colour="
    if(~index)
 
        return llDeleteSubString( src, index, -1);
 
    return src;
</div></div>
}</source>
<div id="box">
|helpers
== Specification ==
|also_functions
<div style="padding: 0.5em;">
|also_events
<lsl>
|also_tests
string left (string src, string divider) {
|also_articles
      integer iStart = llSubStringIndex( src, divider ) + 1;  
|location
      string result = llGetSubString( src, 0, iStart -1) ;//note -2 here if you don't want the divider included in what you get back
|notes
      return result;
|cat1=Examples
}
|cat2=String
</lsl>
|cat3
</div></div>
|cat4
 
}}
{{LSLC|Examples|left}}

Latest revision as of 15:24, 24 January 2015

Summary

Function: string left( string src, string divider );

Returns text left of a specified separator
Returns a string that is the text in src that is left of the first occurrence of divider.

• string src
• string divider

If divider is not found then src is returned in it's entirety.

See also: Right

Specification

string left(string src, string divider) {
    integer index = llSubStringIndex( src, divider );
    if(~index)
        return llDeleteSubString( src, index, -1);
    return src;
}

Examples

string value = left("Colour=Brown", "="); //value == "Colour"