Skip to Content
avatar image
Former Member

error - string index out of range 9 in UDF

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

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

4 Answers

  • avatar image
    Former Member
    Dec 16, 2014 at 02:25 PM

    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

    Add comment
    10|10000 characters needed characters exceeded

  • Dec 16, 2014 at 02:36 PM

    Hi Mrityunjoy,

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

    Regards

    Anupam

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Dec 16, 2014 at 06:38 PM

    you need to change your udf like below

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

    Add comment
    10|10000 characters needed characters exceeded

  • Dec 17, 2014 at 11:21 AM

    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

    Add comment
    10|10000 characters needed characters exceeded