ID:195091
 
//  Title: String Reversal
// Credit to: Jtgibson
// Modified by: Hiead
// Contributed by: Hiead

/*
I decided to modify the snippet because there are a few modifications
that either should or could be made to it. For one, the lentext() proc
is obsolete to length. While in practice it may/may not have been edited
out to run the same way as length(), it -may- eventually be phased out
and wouldn't be nice to teach people obsolete functions.

The "reverse" var is also unneeded, as there is already a variable
that is returned by default: the . variable. We may as well use the
freebies given to us by DM.

While the second edit isn't all too significant, I feel the first is
noteworthy enough that a modification is in order. I'll just happen to
implement the second note as I do the first. This second version should
also be faster than the first.

Also, it may be wise to make sure that the argument is indeed text
with the istext() proc, but unless the programmer is a dunce, they
shouldn't really make such a silly mistake. However, due to the
ambiguously named proc, such confusion may occur with things where
the programmer might try to reverse(list). Because of this, I'll try
to use a more logical name for the proc.

*/


proc/reverseText(string)
for(var/index = length(string), index > 0, index--)
. += ascii2text(text2ascii(string, index))


///*
// Testing Code/Sample Implementation:

client/verb/backwards_text(T as text)
if(T)
src << reverseText("[key]: [T]")

//*/


Hiead
I detached this from the other String Reversal thread and made it its own post, in keeping with the new one-snippet-per-topic guideline.

"Faster" is undoubtedly on the order of a millisecond or two every several billion uses of the proc, and until the function actually becomes unsupported it doesn't really matter what is being used. =P

In summary, I think this is well beyond excessive, to be honest, but more power to you. ;-P