
Specialist III
2010-11-14
09:00 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
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
634 Views
4 Replies

Anonymous
Not applicable
2010-11-14
11:18 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
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.
634 Views

Specialist III
2010-11-14
11:43 AM
Author
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
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
634 Views

Anonymous
Not applicable
2010-11-14
01:23 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
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.
634 Views

Specialist
2010-11-14
05:20 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You could just use a tReplace component. It does a regular expressions search so use " \\((\\d\\.)+\\)" as your search string and replace with "".
634 Views
