Difference between revisions of "StringReverse"

From Second Life Wiki
Jump to navigation Jump to search
m (moved UStringRev to StringReverse: conformance to naming standards of user defined functions)
m (tweaked)
Line 2: Line 2:
<div style="float:right;">__TOC__</div>
<div style="float:right;">__TOC__</div>
{{void-box
{{void-box
|title=[[:Category:LSL_User-Defined_Functions|User-Defined Function]]: [[string]] uStringReverse( [[string]] ''vStrSrc'' );
|title=<div id="box" style="display:none"><h2>Summary</h2></div>[[:Category:LSL_User-Defined_Functions|User-Defined Function]]: [[string]] uStringReverse( [[string]] ''vStrSrc'' );
|content=
|content=
Returns a string that is ''vStrSrc'' with the characters in reverse order
Returns a string that is ''vStrSrc'' with the characters in reverse order
* ''vStrSrc'': source string to reverse
* ''vStrSrc'': source string to reverse
}}


{{void-box
 
|title=Code:
'''Smaller Code:'''
|content=
'''Smaller version'''
* LSO: 169 bytes
* LSO: 169 bytes
* MONO: 512 bytes
* MONO: 512 bytes
Line 28: Line 25:
/*//--                                                                --//*/</lsl><!-- Please do not remove license statement -->
/*//--                                                                --//*/</lsl><!-- Please do not remove license statement -->


'''Faster version'''
'''Faster Code:'''
* LSO: 184 bytes
* LSO: 184 bytes
* MONO: 512 bytes
* MONO: 512 bytes
Line 46: Line 43:


{{void-box
{{void-box
|title=Caveats:
|title=Caveats
|content=
|content=
* The "Faster" version doubles the string size internally, and is more likely to cause a stack/heap collision(script crash) with large strings and/or limited free memory
* The "Faster" version doubles the string size internally, and is more likely to cause a stack/heap collision(script crash) with large strings and/or limited free memory
}}
}}
[[Category:LSL_User-Defined_Functions]]
[[Category:LSL_User-Defined_Functions]]

Revision as of 03:12, 29 May 2010

User-Defined Function: string uStringReverse( string vStrSrc );

Returns a string that is vStrSrc with the characters in reverse order

  • vStrSrc: source string to reverse


Smaller Code:

  • LSO: 169 bytes
  • MONO: 512 bytes

<lsl>string uStringReverse( string vStrSrc ){

   integer vIntCnt = llStringLength( vStrSrc );
   while (vIntCnt){
       vStrSrc += llGetSubString( vStrSrc, (vIntCnt = ~-vIntCnt), vIntCnt );
       vStrSrc = llDeleteSubString( vStrSrc, vIntCnt, vIntCnt );
   }
   return vStrSrc;

} /*//-- Anti-License Text --//*/ /*// Contributed Freely to the Public Domain without limitation. //*/ /*// 2009 (CC0) [ http://creativecommons.org/publicdomain/zero/1.0 ] //*/ /*// Void Singer [ https://wiki.secondlife.com/wiki/User:Void_Singer ] //*/ /*//-- --//*/</lsl>

Faster Code:

  • LSO: 184 bytes
  • MONO: 512 bytes

<lsl>string uStringReverse( string vStrSrc ){

   integer vIntCnt = llStringLength( vStrSrc );
   while (vIntCnt){
       vStrSrc += llGetSubString( vStrSrc, (vIntCnt = ~-vIntCnt), vIntCnt );
   }
   return llGetSubString( vStrSrc, llStringLength( vStrSrc ) >> 1, 0xFFFFFFFF );

} /*//-- Anti-License Text --//*/ /*// Contributed Freely to the Public Domain without limitation. //*/ /*// 2009 (CC0) [ http://creativecommons.org/publicdomain/zero/1.0 ] //*/ /*// Void Singer [ https://wiki.secondlife.com/wiki/User:Void_Singer ] //*/

/*//-- --//*/</lsl>

Caveats

  • The "Faster" version doubles the string size internally, and is more likely to cause a stack/heap collision(script crash) with large strings and/or limited free memory