Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
How to extract a word before records in a string?
String1: Test md records.
String2: 123 primary total records to count.
String3: Test records in file 123records.txt.
Extract as follow:
String1: md
String2: total
String3: test
Hi
Assuming these string value comes from a data source, try this expression on tJavaRow:
output_row.columnName=((input_row.columnName.substring(0, input_row.columnName.indexOf("records"))).trim()).substring(((input_row.columnName.substring(0, input_row.columnName.indexOf("records"))).trim()).lastIndexOf(" "));
Let me know if you it works?
Regards
Shong
Hi
Assuming these string value comes from a data source, try this expression on tJavaRow:
output_row.columnName=((input_row.columnName.substring(0, input_row.columnName.indexOf("records"))).trim()).substring(((input_row.columnName.substring(0, input_row.columnName.indexOf("records"))).trim()).lastIndexOf(" "));
Let me know if you it works?
Regards
Shong
You could also use regex expression with java replaceAll function like below :
YourInputString.replaceAll( "^(.*?)([A-Za-z]+)(\\s*)(records)(.*?)$", "$2" )
Thanks this solution worked and only thing I needed to do is to add a replaceall to trim the spaces coming before the output word.
output_row.columnName=((input_row.columnName.substring(0, input_row.columnName.indexOf("records"))).trim()).substring(((input_row.columnName.substring(0, input_row.columnName.indexOf("records"))).trim()).lastIndexOf(" ")).replaceAll(" ", "");