Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi
I have a flat file and on each row I want to capture the string value from position 81 to position 111
Below is my job
I am passing variable ReportName to tFileOutputDelimited.
The value for this variable is always between position 81 through 111 character in each row of the file.
Below are 2 expressions I wrote for ReportName but ain't getting what I want
Tried Option 1)
row1.line != null && row1.line.length() > 81 ? row1.line.substring(81) : row1.line.substring(111)
This does not stop at position 111 and goes to the end of the row and selects everything
Tried Option 2)
row1.line != null && row1.line.length() > 81 ? row1.line.substring(81:111)
Gives error message
Syntax error, insert ": Expression" to complete Expression
Syntax error on token ":", invalid AssignmentOperator
Can someone please help?
How can I capture string value from character position 81 through 111 of a delimited flat file?
Thank you
index 111 doesnt exist if row1.line length is under 111 so you can try somethig like that :
(row1.line != null && row1.line.length() > 81)?(row1.line.substring(81,(row1.line.length()<111)?row1.line.length():111)):null
so if row1.line length is under 111 it will take the last index of the string for substring
Hi,
(row1.line != null && row1.line.length() > 81)?StringHandling.SUBSTR(row1.line, 81,30):null
Send me love and Kidos
Hi gjeremy,
Thank you for your quick response. Truly Appreciated.
I tried your solution and get syntax error message
I have Talend 6.2 version and StringHandling.SUBSTR is not an option for me
Below is the error I get
The method SUBSTR(String, int, int) is undefined for the type StringHandling
Syntax error on token ":", invalid AssignmentOperator
Syntax error, insert ": Expression" to complete Expression
Try this expression:
(row1.line != null && row1.line.length() > 81)?row1.line.substring(81,111):null
Yes StringHandling.SUBSTR appear after 6.2,
(row1.line != null && row1.line.length() > 111)?row1.line.substring(81,111):null
send me Love and Kudos
Hi Shong and GJeremy,
I tried your suggestion and it works if character position until 111 exists.
However if string value exists from 81 to 92 then I get "out of range error
Here is how my data is
RP2956RPA591040000030300000000872000000000000000000000000000000000000005/04/2021GPA REPORT CE TUESDAY MAY
RP2956RPA591040000030300000000872000000000000000000000000000000000000005/04/2021GPA REPORT R STORE.
1RP2956RPA591040000030300000000872000000000000000000000000000000000000005/04/2021GPA REPORT RP02956
0RP3227MAN241020000002400000009470902000000000000000000000000000000000005/04/2021STORE MANIFEST SKU SUMMARY
RP3227MAN241020000002400000009470902000000000000000000000000000000000005/04/2021STORE MANIFEST SKU SUMMARY
RP2956RPA591040000030300000000872000000000000000000000000000000000000005/04/2021HELLO WORLD
RP2738PSN613100000002400000009475124000000000000000000000000000000000005/04/2021P.O. STORE PACKING NOTE: 1
So from above data your expression catches following
GPA REPORT
STORE MANIFEST
But as soon as it reaches line # 6 HELLO WORLD it throws out of range error.
String stops at 93 and expression is looking for range from 81 to 111
1) I have made following changes to the expression to TRIM any characters
(row1.line != null && row1.line.length() > 81)?StringHandling.TRIM(row1.line.substring(81,111)):null
Error as below -
java.lang.StringIndexOutOfBoundsException: String index out of range: 111
at java.lang.String.substring(Unknown Source)
Thank you so much for your help. Truly appreciated.
index 111 doesnt exist if row1.line length is under 111 so you can try somethig like that :
(row1.line != null && row1.line.length() > 81)?(row1.line.substring(81,(row1.line.length()<111)?row1.line.length():111)):null
so if row1.line length is under 111 it will take the last index of the string for substring
BOOM!!!! The expression worked
Thank you so much GJeremy
Truly Appreciated the quick response from both of you Shong and GJeremy!
you can also just use : row1.line.replaceAll(".*\\/\\d{4}","");
it can work if you dont have a date like dd/MM/yyyy in your report name