Skip to Content
avatar image
Former Member

Substring

Hi Group,

I have a field length of 12 character,to multiply last 12th character with 2 I am using

<b>

Integer.parseInt(a[j].substring(11,12)) * 2

</b> in Java UDF

but it is giving the error that index out of range?

Can any body suggest what is the wrong I am doing in the above statement

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

2 Answers

  • avatar image
    Former Member
    Feb 28, 2007 at 06:10 PM

    please use..

    Integer.parseInt(a[j].substring(11)) * 2

    The java indexing starts from 0 ..so for a 12 character long string the last index is 11...

    Thanks.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Feb 28, 2007 at 06:10 PM

    Hi swabap,

    Use

    Integer.parseInt(a[j].substring(10,11)) * 2

    in Java UDF

    because in java the first char starts with 0

    Regards,

    Akshay

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hi,

      yes please use:

      Integer.parseInt(a[j].substring(10,11)) * 2

      as the standard format of subtring() function is:

      "substring(start,end)" and in case of java the index starts from '0'

      But there is one <b>more imp</b> thing that the value of a[j] should'nt be less than 12 chars and this is a must condition or it will throw an error.

      If there is a possibility of the chars in a[j] will be less than 12 then u can pad it and make it 12 chars.u will need one more udf or u can use the same udf and add the padding function in it.

      Ranjit.