Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
I have two columns (tmysqloutput) that I will get the value from only one column (tmysqlinput) depends on the condition, when I tried to run with to one column first, everything are working perfectly, but then when I load the expression on the second column, I got this error:
Exception in component tMap_4 (FileExtractAndLoad)
java.lang.StringIndexOutOfBoundsException: String index out of range: 40
at java.lang.String.substring(Unknown Source)
My expression syntax for the column that throwing that error is:
row5.ADDRESS.contains("%TOSL%") ? row5.ADDRESS.substring(0,4): ((row5.ADDRESS.substring((row5.ADDRESS.indexOf("to") + 3),(row5.ADDRESS.indexOf("to") + 10))).replace("-", "").replaceAll("\\D*",""))
While the first one is this:
row5.ADDRESS.contains("%Refer%") ? row5.ADDRESS.substring(0,4): ((row5.ADDRESS.substring((row5.ADDRESS.indexOf("ABC") + 4),(row5.ADDRESS.indexOf("ABC") + 11))).replace("-", "").replaceAll("\\D*",""))
Is there any possible way on how ti fix this? And if there's a way, I need to implement it on both expression?
Thanks!
Thanks for taking time to response on my question, I fixed this by doing the code below:
row5.ADDRESS.contains("%REFER%") ? row5.ADDRESS.trim(): ((row5.ADDRESS.substring(row5.ADDRESS.indexOf("ABC") +4, Math.min(row5.ADDRESS.indexOf("ABC") + 11, row5.ADDRESS.length())).replace("-","").replaceAll("\\D","")))
The key is to use the "Math.min and length"
What do you mean? Sorry, but is that a serious answer?
Yes, although on looking at your post again, I think I switched the expression that works with the one that doesn't. The one that works is:
row5.ADDRESS.contains("%Refer%") ? row5.ADDRESS.substring(0,4): ((row5.ADDRESS.substring((row5.ADDRESS.indexOf("ABC") + 4),(row5.ADDRESS.indexOf("ABC") + 11))).replace("-", "").replaceAll("\\D*",""))
correct? And for the second expression, you copied this and updated the "index numbers", right?
row5.ADDRESS.contains("%TOSL%") ? row5.ADDRESS.substring(0,4): ((row5.ADDRESS.substring((row5.ADDRESS.indexOf("to") + 3),(row5.ADDRESS.indexOf("to") + 10))).replace("-", "").replaceAll("\\D*",""))
I think the issue is with row5.ADDRESS.substring(0,4); the row5.ADDRESS.contains("%TOSL%") can return a string of length 3 ("TOSL"), so it should be row5.ADDRESS.substring(0,3). Otherwise, when it returns "TOSL", you're trying to read position 4 in a zero-indexed string, which is out of bounds.
Hope this helps.
Thanks for taking time to response on my question, I fixed this by doing the code below:
row5.ADDRESS.contains("%REFER%") ? row5.ADDRESS.trim(): ((row5.ADDRESS.substring(row5.ADDRESS.indexOf("ABC") +4, Math.min(row5.ADDRESS.indexOf("ABC") + 11, row5.ADDRESS.length())).replace("-","").replaceAll("\\D","")))
The key is to use the "Math.min and length"