cancel
Showing results for 
Search instead for 
Did you mean: 

Substring

Former Member
0 Kudos

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

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

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

ranjit_deshmukh
Active Participant
0 Kudos

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.

Former Member
0 Kudos

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.