Difference between revisions of "StringReverse"
Void Singer (talk | contribs) m (Moved out of user page) |
Void Singer (talk | contribs) m (tweaks) |
||
Line 1: | Line 1: | ||
{{LSL Header|[[:Category:LSL_User-Defined_Functions|User-Defined Functions]]|[[User:Void_Singer|Void's User Page]]}} | {{LSL Header|[[:Category:LSL_User-Defined_Functions|User-Defined Functions]]|[[User:Void_Singer|Void's User Page]]}} <!-- please do not remove added links --> | ||
<div style="float:right;">__TOC__</div> | |||
{{void-box | {{void-box | ||
|title=[[Function]]: [[string]] uStringRev( [[string]] ''vStrSrc'' ); | |title=[[Function]]: [[string]] uStringRev( [[string]] ''vStrSrc'' ); | ||
Line 25: | Line 26: | ||
/*// 2009 (CC0) [ http://creativecommons.org/publicdomain/zero/1.0 ] //*/ | /*// 2009 (CC0) [ http://creativecommons.org/publicdomain/zero/1.0 ] //*/ | ||
/*// Void Singer [ https://wiki.secondlife.com/wiki/User:Void_Singer ] //*/ | /*// Void Singer [ https://wiki.secondlife.com/wiki/User:Void_Singer ] //*/ | ||
/*//-- --//*/</lsl> | /*//-- --//*/</lsl><!-- Please do not remove license statement --> | ||
'''Faster version''' | '''Faster version''' | ||
Line 41: | Line 42: | ||
/*// 2009 (CC0) [ http://creativecommons.org/publicdomain/zero/1.0 ] //*/ | /*// 2009 (CC0) [ http://creativecommons.org/publicdomain/zero/1.0 ] //*/ | ||
/*// Void Singer [ https://wiki.secondlife.com/wiki/User:Void_Singer ] //*/ | /*// Void Singer [ https://wiki.secondlife.com/wiki/User:Void_Singer ] //*/ | ||
/*//-- --//*/</lsl> | /*//-- --//*/</lsl><!-- Please do not remove license statement --> | ||
}} | }} | ||
{{void-box | {{void-box | ||
|title= | |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]] |
Revision as of 01:52, 29 May 2010
LSL Portal | Functions | Events | Types | Operators | Constants | Flow Control | Script Library | Categorized Library | Tutorials | User-Defined Functions | Void's User Page |
Function: string uStringRev( string vStrSrc );
Returns a string that is vStrSrc with the characters in reverse order
- vStrSrc: source string to reverse
Code:
Smaller version
- LSO: 169 bytes
- MONO: 512 bytes
<lsl>string uStringRev( 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 version
- LSO: 184 bytes
- MONO: 512 bytes
<lsl>string uStringRev( 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