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 GARTNER 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

Best Practices for Using Context Variables with Talend – Part 1

Learn how to do cool things with Context Variables

Blog

Migrate Data from one Database to another with one Job using the Dynamic Schema

Find out how to migrate from one database to another using the Dynamic schema

Blog

Best Practices for Using Context Variables with Talend – Part 4

Pick up some tips and tricks with Context Variables

Blog