cancel
Showing results for 
Search instead for 
Did you mean: 

User Defined Function

Former Member
0 Kudos

Hi,

My UDFscenario is to get the prepend zero's for array of string. I am passing the String[] as input for prepend zero function.please provide me a code.

Accepted Solutions (0)

Answers (2)

Answers (2)

former_member189441
Active Participant
0 Kudos

Hi,

If u have same length (for example in this code i assumed as 20 ) Strings in your input array..then this code will work

Take type of UDF as queue type

then the UDF will be of type void

Use this code

Here a[] =input array

b[] =output array

so here you have to pass 2 arguments to your UDF


for(int i=0;i<a.length;i++)
{ 

int Arraylength=a<i>.length();
 int length=20-Arraylength;
 if(length>0)
{
String temp="";
for(int i=0;i<length;i++)
temp=temp.concat("0");
}

b<i>=temp.concat(a<i>);
result.addValue(b<i>);
}
}

former_member183906
Active Contributor
0 Kudos

Hii

1) A clean solution for this avoiding cutom UDFs is using formatNumber arithmetic function with the format "000000000000000000".

It will format the number padding 0.

2)

If u want really to write UDF :

String strE = "12";

int lenE = strE.length();

for(int i=0;i<18-lenE;i++){

strE="0"+strE;

}

return(strE);