//Title: String Reversal
//Contributed by: Jtgibson
//Credit to: Jtgibson
/*
Flips a text string backwards. Useful for spoilers, hints, or just for the heck
of it.
Note: This function is actually impossible to make more efficient in DM, but
(some) other programming languages have a much more efficient method. They work
by swapping the beginning and end characters, and working their way into the
middle. This saves memory and only does half of the work. BYOND is incapable
of such efficiency because its strings are immutable, meaning you can't edit the
characters belonging to a string directly.
Hopefully that'll change in the future...
*/
proc/reverse(string)
var/reverse = ""
for(var/i = lentext(string), i > 0, i--)
reverse += copytext(string, i, i+1)
return(reverse)
///*
//Testing code/sample implementation:
mob/verb/backwards_text(T as text)
usr << reverse("[usr.name]: [T]")
//*/
ID:195101
Nov 21 2006, 9:07 am
|
|