Difference between revisions of "Right"

From Second Life Wiki
Jump to navigation Jump to search
(style, optimization and bug fixes.)
m (Replaced <source> with <syntaxhighlight> (and some minor things, mostly to keep code styling uniform))
 
(6 intermediate revisions by 4 users not shown)
Line 4: Line 4:
|p1_type=string|p1_name=src
|p1_type=string|p1_name=src
|p2_type=string|p2_name=divider
|p2_type=string|p2_name=divider
|return_type=integer
|return_type=string
|return_text=that is the text in '''src''' that is right of the first occurrence of '''divider'''.  
|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_desc=Returns text right of a specified separator
|func_footnote=
|func_footnote=
You can, for example, loop through a list, passing it extracted values from the list and the mask, and it will let you pull out items from the list which are a valid match according to the mask criteria you specified.
If '''divider''' is not found, then '''src''' is returned in its entirety.
 
If '''divider''' is not found then '''src''' is returned in it's entirety.


See also: [[Left]]
See also: [[Left]]
|examples=
|examples=
<lsl>string value = right("Colour=Brown", "="); //value == "Brown"</lsl>
<syntaxhighlight lang="lsl2">string value = right("Colour=Brown", "="); //value == "Brown"</syntaxhighlight>
|spec=<lsl>string right(string src, string divider) {
|spec=<syntaxhighlight lang="lsl2">string right(string src, string divider) {
     integer index = llSubStringIndex( src, divider );
     integer index = llSubStringIndex(src, divider);
     if(~index)
     if (~index) {
         return llDeleteSubString( src, 0, index + llStringLength(divider) - 1);
         return llDeleteSubString(src, 0, index + llStringLength(divider) - 1);
    }
     return src;
     return src;
}</lsl>
}</syntaxhighlight>
|helpers
|helpers
|also_functions
|also_functions
Line 26: Line 25:
|also_tests
|also_tests
|also_articles
|also_articles
|location=
|location
Posted here with the kind permission of {{User|Very Keynes}}. Originally posted February 2008 at http://forums.secondlife.com/showthread.php?t=243445 .
|notes
|notes
|cat1=Examples
|cat1=Examples
|cat2
|cat2=String
|cat3
|cat3
|cat4
|cat4
}}
}}

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"