cancel
Showing results for 
Search instead for 
Did you mean: 

error - string index out of range 9 in UDF

Former Member
0 Kudos

Hi i am getting following error in udf - string index out of range 9 from substring function from following code -

str = str1.substring(0, 9); kindly give solution for it.

Thanks

Mrityunjoy

Accepted Solutions (0)

Answers (4)

Answers (4)

azharshaikh
Active Contributor
0 Kudos

Hi,

You can achieve this using a UDF or with Std Graphical mapping (if there are no further complex checks involved)

1. An alternative approach would be as follows. This UDF will not give you errors when length is Less than 9, nor it will fail if the Source node is absent/ empty

str = str1.substring(0, Math.min(9, str1.length()));

2. You can achieve this using std Graphical mapping as well as follows:

Regards,

Azhar

Former Member
0 Kudos

you need to change your udf like below

if(str1.length() > 10) then use str1.substring(0,9) else str1.

anupam_ghosh2
Active Contributor
0 Kudos

Hi Mrityunjoy,

                   This error will only result. if the length of the input string (str1) string is less than 10 characters.

Regards

Anupam

Former Member
0 Kudos

Hi,

Is your str1 greater than or equal to 10 characters? Please check all the values in the context.

If not you will get this error.

Thanks,

Sudhansu