StringHandling.RIGHT doesn't work as it should

Six Stars

StringHandling.RIGHT doesn't work as it should

Hello,

 

My input is a row with some Line Feed and Carriage Return.

 

Input value : "RPT-GL2-098


surname.name"

 

My first treatment replace all the LF and CR by space

 

row1.BRANCH_CODE.replaceAll("(?:\\n|\\r)", " ") as Var.NAME_1

 

Output : "RPT-GL2-098   surname.name"

 

My second treatment replace all space by a '#' (it can be another special char, just used to be detected by INDEX)

 

Var.NAME_1.replaceAll("\\s{2,}", "#") as Var.NAME_2

 

Output : "RPT-GL2-098#surname.name"

 

In my final treatment, I want to extract "surname.name" by taking all the string at the right of the char '#':

 

StringHandling.RIGHT(Var.NAME_2,StringHandling.INDEX(Var.NAME_2,"#")) 

Output I want : "surname.name"

It work for one case, but it truncate in other case (There's 11 char a the LEFT of the # for my first row and my output is 11 char max).

Output I have : "surname.name" for the first occurence (11char)

On the others outputs even if there's more or less than 11 char, I have a 11 char string.

When it's less than 11 char I have something like "GL2-098#.name"

 

I don't understand what's wrong. RIGHT is supposed to take the n char after the INDEX, but he take only 11 (and my INDEX = 11 on my first row)

 

Maybe it's not dynamic, how can I solve this problem ?

 

Thanks

 


Accepted Solutions
Six Stars

Re: StringHandling.RIGHT doesn't work as it should

Ok my bad I'm tired.

 

So StringHandling.RIGHT(String, n) is taking all the n char from the END RIGHT of the string and not all the char at the RIGHT of the "index" (n).

 

So I solve my case

3 more treatments to calculate how many char I need to extract

StringHandling.LEN(Var.NAME_2) as Var.LENGTH
StringHandling.INDEX(Var.NAME_2,"#") as Var.INDEX
Var.LENGTH -  Var.INDEX -1 as Var.LENGTH_MIN_INDEX

And my final treatment :

StringHandling.RIGHT(Var.NAME_2,Var.LENGTH_MIN_INDEX)   

 

View solution in original post


All Replies
Six Stars

Re: StringHandling.RIGHT doesn't work as it should

Ok my bad I'm tired.

 

So StringHandling.RIGHT(String, n) is taking all the n char from the END RIGHT of the string and not all the char at the RIGHT of the "index" (n).

 

So I solve my case

3 more treatments to calculate how many char I need to extract

StringHandling.LEN(Var.NAME_2) as Var.LENGTH
StringHandling.INDEX(Var.NAME_2,"#") as Var.INDEX
Var.LENGTH -  Var.INDEX -1 as Var.LENGTH_MIN_INDEX

And my final treatment :

StringHandling.RIGHT(Var.NAME_2,Var.LENGTH_MIN_INDEX)   

 

View solution in original post

2019 GARTNER MAGIC QUADRANT FOR DATA INTEGRATION TOOL

Talend named a Leader.

Get your copy

OPEN STUDIO FOR DATA INTEGRATION

Kickstart your first data integration and ETL projects.

Download now

Best Practices for Using Context Variables with Talend – Part 1

Learn how to do cool things with Context Variables

Blog

Migrate Data from one Database to another with one Job using the Dynamic Schema

Find out how to migrate from one database to another using the Dynamic schema

Blog

Best Practices for Using Context Variables with Talend – Part 4

Pick up some tips and tricks with Context Variables

Blog