on 03-27-2011 4:09 PM
Hi Experts,
I have return UDF. but for me it is giving the index out of bound exception.
From Source field i need last 4 characters needs to populate in the target field.
public String ModelCode(String SGTXT,Container container){
int len=0;
int len1=0;
String result=" ";
len= SGTXT.length( );
len1 = len-4;
result = SGTXT.substring(len1,len);
return result;
}
cuold you please help me out.
Regards,
Prabhakar.A
Try this to avoid exception....
public String ModelCode(String SGTXT,Container container){
int length = SGTXT.length();
if(length < 4){
return "";
}
return SGTXT.substring(length-4);
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
In your code check if len GE 4 then only disply the results. What is happening now, whenever the length is less than 4 "substring" throws an exception. So use below code..
public String ModelCode(String SGTXT,Container container){
int len=0;
int len1=0;
String res =" ";
len= SGTXT.length( );
if(len GE 4)
{
len1 = len-4;
res = SGTXT.substring(len1,len);
}
return res;
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
80 | |
24 | |
11 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.