Difference between revisions of "Left"
Jump to navigation
Jump to search
m |
m (added to Category:LSL String) |
||
Line 1: | Line 1: | ||
{{ | {{LSL Header}} __NOTOC__ | ||
<div id="box"> | |||
== Function: [[string]] left([[float]] {{LSL Param|num}}, [[integer]] {{LSL Param|places}} , [[string]] {{LSL Param|rnd}}); == | |||
<div style="padding: 0.5em;"> | |||
| | Returns text left of a specified separator | ||
See also: [[Right]] | See also: [[Right]] | ||
< | Example:<br /> | ||
string notecardparameter = left(sdata,"="); | |||
//in a notecard line that reads Colour=Brown, returns "Colour=" | |||
}</lsl> | </div></div> | ||
<div id="box"> | |||
== Specification == | |||
<div style="padding: 0.5em;"> | |||
<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> | |||
</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 02:28, 2 May 2011
LSL Portal | Functions | Events | Types | Operators | Constants | Flow Control | Script Library | Categorized Library | Tutorials |
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 )