cancel
Showing results for 
Search instead for 
Did you mean: 

UDF help

Former Member
0 Kudos

Hi,

Have a source field whose length can be of 40 char,the target field should be 30 chars long, If shorter than 30 it should be padded with trailiing spaces to 30 chars.

Can anybody please give me UDF please points guaranteed, Please help needed.Thank you.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

HI,

Use the following UDF with input first string source field,30( a number how much length the target should contain.

<b>Inputs : String a,String b</b>

while (a.length() < Integer.parseInt(b.trim())){

a = a + " ";

}

return a;

}

Regards

Chilla..

<i>points rewarded if it is usefull..</i>

Answers (3)

Answers (3)

Former Member
0 Kudos

input A we are passing string A as Input to UDF.

int i=0;

i=a.length();

if (a.length() >= 40)

return a;

else

{

int j= 40 - i;

for (int k=0; k<=j; j++)

{a=a+" ";}

return a;

}

Regards

Sreeram.G.Reddy

Shabarish_Nair
Active Contributor
0 Kudos

try this !!!

int len = 30;

StringBuffer sBuf= new StringBuffer(a);

int originalLen = sBuf.length() ;

while (origiinalLen < len) {

sBuf.insert(originalLen,'0');

}

String resultstring = sBuf.toString();

return resultstring;

Former Member
0 Kudos

Hi John,

do below: create a simple UDF - It should have String return type. Take a as input String.

if (a.length()>30)

return a.substring(0,30);

else

{

String b;

b=a;

int z = b.length();

for (int i=0;i<(30-z);i++)

b=b+' ';

return b;

}

Thanks,

Rajeev Gupta

Message was edited by:

RAJEEV GUPTA

Message was edited by:

RAJEEV GUPTA