Four Stars

[resolved] tMap Expression filter - compare substrings with variable length

I am looking to compare a fixed string with a variable string that can be of different sizes. Let's say that I want to filter rows that matches the following criteria:
Expression filter:
"abcd".compareTo(a.substring(0, 4)) // where a is a string with variable length

The problem arrises when a="ab" or whenewer its length is lower than 4 characters. In this case "index out of bound exception" is thrown.

I can solve this with first chechking the variable string lenght but I am looking for a cleaner solution.
1 ACCEPTED SOLUTION

Accepted Solutions
Four Stars

Re: [resolved] tMap Expression filter - compare substrings with variable length

I have found a better solution in a library StringHandling from Talend. Above problem can be solved with INDEX method which rerutns a starting position of the compared string.
ex:
StringHandling.INDEX(a,"abcd")
same but in Java:
a.indexOf("abcd")
1 REPLY
Four Stars

Re: [resolved] tMap Expression filter - compare substrings with variable length

I have found a better solution in a library StringHandling from Talend. Above problem can be solved with INDEX method which rerutns a starting position of the compared string.
ex:
StringHandling.INDEX(a,"abcd")
same but in Java:
a.indexOf("abcd")