Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi all
I would like to extract all characters of a string before a certain character (eg. "-" or " ").
I used tJavaRow for this with the following code:
if((row3.street== null) || ("".equals(row3.street )) || row3.street.isEmpty() && ((String)input_row.street).contains("-"))
output_row.street = StringHandling.LEFT(input_row.street,StringHandling.INDEX(input_row.street,"("));
else if((input_row.street) != null && !((String)input_row.street).contains("("))
output_row.street = input_row.street;
I keep getting this out of bounds for lengths error and could t find a fix. Could you help me out here?
Exception in component tJavaRow_1 (Extract_Country_Code)
java.lang.StringIndexOutOfBoundsException: Range [0, -1) out of bounds for length 15
at java.base/jdk.internal.util.Preconditions$1.apply(Preconditions.java:55)
at java.base/jdk.internal.util.Preconditions$1.apply(Preconditions.java:52)
at java.base/jdk.internal.util.Preconditions$4.apply(Preconditions.java:213)
at java.base/jdk.internal.util.Preconditions$4.apply(Preconditions.java:210)
at java.base/jdk.internal.util.Preconditions.outOfBounds(Preconditions.java:98)
at java.base/jdk.internal.util.Preconditions.outOfBoundsCheckFromToIndex(Preconditions.java:112)
at java.base/jdk.internal.util.Preconditions.checkFromToIndex(Preconditions.java:349)
at java.base/java.lang.String.checkBoundsBeginEnd(String.java:4589)
at java.base/java.lang.String.substring(String.java:2703)
at routines.StringHandling.LEFT(StringHandling.java:229)
Thank you very much!
Something like this should work.....
(row3.street!=null&&row3.street.trim().equals("")==false) ? row3.street.indexOf('-')>-1 ? row3.street.substring(row3.street.indexOf('-')+1) : row3.street.indexOf(' ')>-1 ? row3.street.substring(row3.street.indexOf(' ')+1) : row3.street : row3.street
I think this is what you need.....
(row3.street!=null&&row3.street.trim().equals("")==false) ? row3.street.indexOf('-')>-1 ? row3.street.substring(0,row3.street.indexOf('-')) : row3.street.indexOf(' ')>-1 ? row3.street.substring(0, row3.street.indexOf(' ')) : row3.street : row3.street
Hi Shall,
thank you very much. This works.
I would like to get the characters after the " " or "-". How to do this?
Something like this should work.....
(row3.street!=null&&row3.street.trim().equals("")==false) ? row3.street.indexOf('-')>-1 ? row3.street.substring(row3.street.indexOf('-')+1) : row3.street.indexOf(' ')>-1 ? row3.street.substring(row3.street.indexOf(' ')+1) : row3.street : row3.street
Thank you very much rhall! It works and understand it now. Thanks!!