Difference between revisions of "SubStringLastIndex"

From Second Life Wiki
Jump to navigation Jump to search
(moved from user space to it's own page)
 
m (tweaked and added byte costs)
Line 9: Line 9:


if ''vStrTst'' is not found in ''vStrSrc'' {{HoverText|-1|negative one, 0x{{LSL_Hex/Write|-1}}}} is returned.<br />the index of the first character is {{HoverText|0|zero}}
if ''vStrTst'' is not found in ''vStrSrc'' {{HoverText|-1|negative one, 0x{{LSL_Hex/Write|-1}}}} is returned.<br />the index of the first character is {{HoverText|0|zero}}


'''Code:'''
'''Code:'''
* LSO: 182 bytes
* MONO: 1024 bytes
<!-- please replace with a similarly licensed version only -->
<!-- please replace with a similarly licensed version only -->
<lsl>integer uSubStringLastIndex( string vStrSrc, string vStrTst ){
<lsl>integer uSubStringLastIndex( string vStrSrc, string vStrTst ){
Line 19: Line 22:
         llList2String(
         llList2String(
           llParseStringKeepNulls( vStrSrc, (list)vStrTst, [] ),
           llParseStringKeepNulls( vStrSrc, (list)vStrTst, [] ),
           -1)
           0xFFFFFFFF ) //-- (-1)
         );
         );
     return (vIdxFnd | (vIdxFnd >> 31));
     return (vIdxFnd | (vIdxFnd >> 31));

Revision as of 12:36, 12 October 2010

User-Defined Function: integer uSubStringLastIndex( string vStrSrc, string vStrTst );

Returns a integer that is the positive index of the last vStrTst within vStrSrc

  • vStrSrc: source string to check
  • vStrTst: string to look for

if vStrTst is not found in vStrSrc -1 is returned.
the index of the first character is 0


Code:

  • LSO: 182 bytes
  • MONO: 1024 bytes

<lsl>integer uSubStringLastIndex( string vStrSrc, string vStrTst ){

   integer vIdxFnd =
     llStringLength( vStrSrc ) -
     llStringLength( vStrTst ) -
     llStringLength(
       llList2String(
         llParseStringKeepNulls( vStrSrc, (list)vStrTst, [] ),
         0xFFFFFFFF ) //-- (-1)
       );
return (vIdxFnd

Caveats

  • Performs a literal match (case sensitive).
    • Wildcards and RegEx are not supported.
  • Attempting to match an empty string ("") will return 0 instead of -1.

Notes

  • This function is operates exactly like llSubStringIndex (including caveats), from the opposite end of the string.