Difference between revisions of "Right"

From Second Life Wiki
Jump to navigation Jump to search
(New page: {{LSL Header}} __NOTOC__ <div id="box"> == Function: string right(string {{LSL Param|src}}, string {{LSL Param|divider}}); == <div style="padding: 0.5em;"> Returns text right o...)
 
m (Replaced <source> with <syntaxhighlight> (and some minor things, mostly to keep code styling uniform))
 
(7 intermediate revisions by 4 users not shown)
Line 1: Line 1:
{{LSL Header}} __NOTOC__
{{LSL_Function
<div id="box">
|mode=user
== Function: [[string]] right([[string]] {{LSL Param|src}}, [[string]] {{LSL Param|divider}}); ==
|func=right
<div style="padding: 0.5em;">
|p1_type=string|p1_name=src
Returns text right of a specified separator
|p2_type=string|p2_name=divider
|return_type=string
|return_text=that is the text in '''src''' that is right of the first occurrence of '''divider'''.  
|func_desc=Returns text right of a specified separator
|func_footnote=
If '''divider''' is not found, then '''src''' is returned in its entirety.


See also: [[Left]]
See also: [[Left]]
 
|examples=
Example:<br />
<syntaxhighlight lang="lsl2">string value = right("Colour=Brown", "="); //value == "Brown"</syntaxhighlight>
 
|spec=<syntaxhighlight lang="lsl2">string right(string src, string divider) {
string notecardparameter = right(sdata,"=");
    integer index = llSubStringIndex(src, divider);
//in a notecard line that reads Colour=Brown, returns "Brown"
    if (~index) {
 
        return llDeleteSubString(src, 0, index + llStringLength(divider) - 1);
 
    }
</div></div>
    return src;
<div id="box">
}</syntaxhighlight>
== Specification ==
|helpers
<div style="padding: 0.5em;">
|also_functions
<lsl>
|also_events
string right (string src, string divider) {
|also_tests
      integer iStart = llSubStringIndex( src, divider ) + 1;
|also_articles
      string result = llGetSubString( src, iStart, llStringLength(src) - 1 ) ;
|location
      return result;
|notes
}
|cat1=Examples
 
|cat2=String
</lsl>
|cat3
</div></div>
|cat4
 
}}
{{LSLC|Examples|right}}

Latest revision as of 04:05, 15 October 2023

Summary

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

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

• string src
• string divider

If divider is not found, then src is returned in its entirety.

See also: Left

Specification

string right(string src, string divider) {
    integer index = llSubStringIndex(src, divider);
    if (~index) {
        return llDeleteSubString(src, 0, index + llStringLength(divider) - 1);
    }
    return src;
}

Examples

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