One Star

how to use substring in talend?

Hi,

how to use substing in talend?
3 REPLIES
One Star

Re: how to use substring in talend?

Hi
public String substring(int beginIndex)
public String substring(int beginIndex, int endIndex)
Here are two Java substring methods under TOS.
For example, row1.value.substring(1,25)
Regards,
Pedro
One Star

Re: how to use substring in talend?

Hello guy,
what if I have a column with URL"s like:
http://www.mydomain-1.com/a/b/c/image1.jpg
http://www.mydomain-2.com/j/u/image2.jpg
.....
http://www.mydomain-x.com/f/r/y/w/image20000.jpg
The ulrs have not the same lenght, domains and subfolders.
How can I substract only the base name of the image, like:
image1.jpg
image2.jpg
...
image20000.jpg
Thank you for your help,
Lucian
One Star

Re: how to use substring in talend?

Hi,
You're obliged to create your function and add it to your talend studio, in repository>code>routine

When your fonction added you will find it in tMap in the category "defined by user".

This is a simple function in java that i have made on Eclipse, i have tested on two exemple and i have the right result that you are looking for.

String Str = new String("http://www.mydomain-1.com/a/b/c/image1.jpg");

System.out.print("Found Index :" );
System.out.println(Str.lastIndexOf("/"));
int beginIndex = Str.lastIndexOf("/")+1;

Str = Str.substring(beginIndex);
System.out.println(Str);

String Str1 = new String("http://www.mydomain-x.com/f/r/y/w/image20000.jpg");

System.out.print("Found Index :" );
System.out.println(Str1.lastIndexOf("/"));
int beginIndex1 = Str1.lastIndexOf("/")+1;

Str1 = Str1.substring(beginIndex1);
System.out.println(Str1);
results :
Found Index :31
image1.jpg
Found Index :33
image20000.jpg
It is an idea and you can adapt and optimize it.
Best regards