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)   

 


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)