Skip to main content
Announcements
A fresh, new look for the Data Integration & Quality forums and navigation! Read more about what's changed.
cancel
Showing results for 
Search instead for 
Did you mean: 
_AnonymousUser
Specialist III

talend trim function

Hi guys
quick question concerning talend string trim
I get user inputs like these
Jan (192.168.2.200)
Jan
Piet (192.169.3.21)
Sam
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
thanx
Labels (2)
4 Replies
Anonymous
Not applicable

StringHandling.LEFT("Jan (192.168.2.200)",StringHandling.INDEX("Jan (192.168.2.200)"," "))
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.
_AnonymousUser
Specialist III
Author

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

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
Anonymous
Not applicable

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);
System.out.println(name);
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.
alevy
Specialist

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