Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Save $650 on Qlik Connect, Dec 1 - 7, our lowest price of the year. Register with code CYBERWEEK: Register
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Reverse a String

Anyone know the best way in Talend to reverse order a string ?
i.e.
ABCD to DCBA
Thanks
Labels (2)
4 Replies
janhess
Creator II
Creator II

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();
}
Anonymous
Not applicable
Author

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.
janhess
Creator II
Creator II

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

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