How to reverse a string value

7 views
Skip to first unread message

secretGeek

unread,
Sep 16, 2009, 10:37:13 PM9/16/09
to World's Simplest Code Generator
Handy little trick i worked out yesterday:

If you want to reverse a term in WSCG, you can use this pattern:

<% $0.split("").reverse().join("") %>


input:

Hello

becomes

olleH


This can also be useful for grabbing text off the end of a term.

Say if you have messages like this:

Fred 15
Fred smith 17
Jack 12

then reversing it and grabbing the first element

<% $0.split("").reverse().join("").split(" ")[0].split("").reverse
().join("") %>

will give you:

15
17
12




Reply all
Reply to author
Forward
0 new messages