One Star

talend trim function

Hi guys
quick question concerning talend string trim
I get user inputs like these
Jan (
Piet (
I would like to remove the ip and the brackets they are in, it seems that SAP records the users like that.
because i would later compare then
i see there is a talend string function but i dont know the parameters
i was thinking of using something like
stringhandling.letf(row1.user_name, 1, ?? where "(" -2 ??)
??i dont know??

any help would be appreciated
Six Stars

Re: talend trim function

StringHandling.LEFT("Jan (",StringHandling.INDEX("Jan ("," "))
Of course you could always create custom Routine under Code folder in Talend, where you could use then custom java import packages and define custom function to handle any of supported datatypes in way you expect.
One Star

Re: talend trim function

Ok im trying to create this routine
public class Main {
public static void main(String[] args) {
String[] names = { "Jan vd Merwe",
"Piet Breedt (",
"Jan vd Merwe (",
"Sarel Fourie (" };
for (String name : names) {
int parIndex = name.indexOf('(');
if (parIndex != -1)
name = name.substring(0, parIndex-1);

got some help from a buddy but he dissapeared on me, how would i change that to work with the a row as input and not the array.

Thanx in advance
Six Stars

Re: talend trim function

In talend left menu, where you create jobs, there is also "Code" folder, under it you right-click on routine and select "Create routine":
delete all content and paste following code into it:
package routines;
public class GetNameWithoutIP {

public static String ReturnName(String name) {
// where do the space char between the name and IP address appears?
int delimiter = name.indexOf("(");
name = name.substring(0, delimiter-1);
return name;
Name the routine in the same way as class name or it would not work.
Then use the routine as standard function of Talend on string column of each row. in the scenario there is tJavaRow used for demonstration, but you could call it everywhere in Talend, tMap expression, etc.
Seven Stars

Re: talend trim function

You could just use a tReplace component. It does a regular expressions search so use " \\((\\d\\.)+\\)" as your search string and replace with "".