One Star

Reverse a String

Anyone know the best way in Talend to reverse order a string ?
i.e.
ABCD to DCBA
Thanks
3 REPLIES
One Star

Re: Reverse a String

I use this routine
/**
* reverseIt() Reverses a string.
*
* {talendTypes} String
*
* {Category} Ncl_routines
*
* {param} string ("fred") input: the string to be reversed
*
* {example} reverseIt("fred") # derf
*
*/
public static String reverseIt(String source) {
int i, len = source.length();
StringBuffer dest = new StringBuffer(len);
for (i = (len - 1); i >= 0; i--)
dest.append(source.charAt(i));
return dest.toString();
}
One Star

Re: Reverse a String

Thanks, I've got this routine but since I'm new to talend I just need a clue on how to apply it and encode it in a tmap function on an incoming string.
One Star

Re: Reverse a String

Under Code create new routine and add the code then use it as you would Talend routines.