Difference between revisions of "Left"

From Second Life Wiki
Jump to navigation Jump to search
m (added to Category:LSL String)
m (<lsl> tag to <source>)
 
(One intermediate revision by one other user not shown)
Line 1: Line 1:
{{LSL Header}} __NOTOC__
{{LSL_Function
<div id="box">
|mode=user
== Function: [[string]] left([[float]] {{LSL Param|num}}, [[integer]] {{LSL Param|places}} , [[string]] {{LSL Param|rnd}}); ==
|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
 
}}
Inspired by (and evolved from) discussions between Cheree Bury & Domino Marama in the SL Scripting Forum July 2008 at http://forums.secondlife.com/showthread.php?t=267884, with optional rounding added (that part being inspired by work by various authors here: https://wiki.secondlife.com/wiki/Fixed_Precision )
 
{{LSLC|Examples|left}}
[[Category:LSL String]]

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"