Difference between revisions of "StringReverse"
Jump to navigation
Jump to search
Void Singer (talk | contribs) m (more tweaks) |
|||
(4 intermediate revisions by 2 users not shown) | |||
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 | ||
'''Smaller Code:''' | |||
* LSO: 158 bytes | |||
'''Smaller | |||
* LSO: | |||
* MONO: 512 bytes | * MONO: 512 bytes | ||
< | <source lang="lsl2">/* //-- Reverse String Order (small version) --// */ | ||
string uStringReverse( string vStrSrc ){ | |||
integer vIntCnt = llStringLength( vStrSrc ); | integer vIntCnt = llStringLength( vStrSrc ); | ||
while (vIntCnt){ | while (vIntCnt){ | ||
vStrSrc | vStrSrc = llDeleteSubString( vStrSrc, vIntCnt, vIntCnt ) + | ||
llGetSubString( vStrSrc, (vIntCnt = ~-vIntCnt), vIntCnt ); | |||
} | } | ||
return vStrSrc; | return vStrSrc; | ||
Line 24: | Line 22: | ||
/*//-- Anti-License Text --//*/ | /*//-- Anti-License Text --//*/ | ||
/*// Contributed Freely to the Public Domain without limitation. //*/ | /*// Contributed Freely to the Public Domain without limitation. //*/ | ||
/*// | /*// 2012 (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 ] //*/ | ||
/*//-- --//*/</ | /*//-- --//*/</source><!-- Please do not remove license statement --> | ||
'''Faster | '''Faster Code:''' | ||
* LSO: 184 bytes | * LSO: 184 bytes | ||
* MONO: 512 bytes | * MONO: 512 bytes | ||
< | <source lang="lsl2">string uStringReverse( string vStrSrc ){ | ||
integer vIntCnt = llStringLength( vStrSrc ); | integer vIntCnt = llStringLength( vStrSrc ); | ||
while (vIntCnt){ | while (vIntCnt){ | ||
Line 42: | Line 40: | ||
/*// 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 ] //*/ | ||
/*//-- --//*/</ | /*//-- --//*/</source><!-- Please do not remove license statement --> | ||
}} | }} | ||
{{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]] |
Latest revision as of 09:35, 10 July 2022
LSL Portal | Functions | Events | Types | Operators | Constants | Flow Control | Script Library | Categorized Library | Tutorials | User-Defined Functions | Void's User Page |
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: 158 bytes
- MONO: 512 bytes
/* //-- Reverse String Order (small version) --// */
string uStringReverse( string vStrSrc ){
integer vIntCnt = llStringLength( vStrSrc );
while (vIntCnt){
vStrSrc = llDeleteSubString( vStrSrc, vIntCnt, vIntCnt ) +
llGetSubString( vStrSrc, (vIntCnt = ~-vIntCnt), vIntCnt );
}
return vStrSrc;
}
/*//-- Anti-License Text --//*/
/*// Contributed Freely to the Public Domain without limitation. //*/
/*// 2012 (CC0) [ http://creativecommons.org/publicdomain/zero/1.0 ] //*/
/*// Void Singer [ https://wiki.secondlife.com/wiki/User:Void_Singer ] //*/
/*//-- --//*/
Faster Code:
- LSO: 184 bytes
- MONO: 512 bytes
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 ] //*/
/*//-- --//*/
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