Reverse a String

One Star

Reverse a String

Anyone know the best way in Talend to reverse order a string ?
i.e.
ABCD to DCBA
Thanks
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.
One Star

Re: Reverse a String

String reverse="";
for(int i=input_row.ReverseString.length()-1 ; i >= 0 ; i--)
{
reverse=reverse+input_row.ReverseString.charAt(i);
}
output_row.ReverseString=reverse;

 

 

write this code in tjavarow 

2019 GARNER MAGIC QUADRANT FOR DATA INTEGRATION TOOL

Talend named a Leader.

Get your copy

OPEN STUDIO FOR DATA INTEGRATION

Kickstart your first data integration and ETL projects.

Download now

What’s New for Talend Summer ’19

Watch the recorded webinar!

Watch Now

Best Practices for Using Context Variables with Talend – Part 4

Pick up some tips and tricks with Context Variables

Blog

How Media Organizations Achieved Success with Data Integration

Learn how media organizations have achieved success with Data Integration

Read

Downloads and Trials

Test drive Talend's enterprise products.

Downloads