Difference between revisions of "Left"

From Second Life Wiki
Jump to navigation Jump to search
m
m (added to Category:LSL String)
Line 1: Line 1:
{{LSL_Function
{{LSL Header}} __NOTOC__
|mode=user
<div id="box">
|func=left
== Function: [[string]] left([[float]] {{LSL Param|num}}, [[integer]] {{LSL Param|places}} , [[string]] {{LSL Param|rnd}}); ==
|p1_type=string|p1_name=src
<div style="padding: 0.5em;">
|p2_type=string|p2_name=divider
Returns text left of a specified separator
|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=
 
<lsl>string value = left("Colour=Brown", "="); //value == "Colour"</lsl>
Example:<br />
|spec=<lsl>string left(string src, string divider) {
 
    integer index = llSubStringIndex( src, divider );
string notecardparameter = left(sdata,"=");
    if(~index)
//in a notecard line that reads Colour=Brown, returns "Colour="
        return llDeleteSubString( src, index, -1);
 
    return src;
 
}</lsl>
</div></div>
|helpers
<div id="box">
|also_functions
== Specification ==
|also_events
<div style="padding: 0.5em;">
|also_tests
<lsl>
|also_articles
string left (string src, string divider) {
|location
      integer iStart = llSubStringIndex( src, divider ) + 1;  
|notes
      string result = llGetSubString( src, 0, iStart -1) ;//note -2 here if you don't want the divider included in what you get back
|cat1=Examples
      return result;
|cat2
}
|cat3
</lsl>
|cat4
</div></div>
}}
 
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]]

Revision as of 03:28, 2 May 2011

Function: string left(float num, integer places , string rnd);

Returns text left of a specified separator

See also: Right

Example:

string notecardparameter = left(sdata,"="); //in a notecard line that reads Colour=Brown, returns "Colour="


Specification

<lsl> string left (string src, string divider) {

      integer iStart = llSubStringIndex( src, divider ) + 1; 
      string result = llGetSubString( src, 0, iStart -1) ;//note -2 here if you don't want the divider included in what you get back
      return result;

} </lsl>

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 )