cancel
Showing results for 
Search instead for 
Did you mean: 

UDF - Right justification

Former Member
0 Kudos

Hi,

I need to create UDF for the right justification of the characters. I've one sample UDF that does the same job but in that UDF the lenght of the string is fixed (20 char). In my requiremens the lenght of the input string is varying.

Please can anyone suggest me how to do this? what are the changes requires in the sample UDF?

Or if anyone has that UDF available please post it or send me.

Here is the sample UDF :

String padChar = " ";

int maxLen = 20;

{

int padLen = str.length();

int sLen = (maxLen - padLen);

if (padLen >= maxLen)

return str;

StringBuffer sb = new StringBuffer(sLen);

for (int count = sLen; count > 0; count--)

{

sb.append(padChar);

}

str = sb.toString() + str;

return str;

}

Regards,

Chintan

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Chintan,

There must be length which should be there for right padding. How will you decide how much padidng is required. Can you give few examples of what you are looking for?

thanks

amit

Answers (4)

Answers (4)

Former Member
0 Kudos

here is the complete udf

String padChar = " ";

int maxLen = Integer.parseInt(maxfieldlenth);

{

int padLen = str.length();

int sLen = (maxLen - padLen);

if (padLen >= maxLen)

return str;

StringBuffer sb = new StringBuffer(sLen);

for (int count = sLen; count > 0; count--)

{

sb.append(padChar);

}

str = sb.toString() + str;

return str;

}

in this UDF I use two input parameters 1) input field 2) length of the input field

Regards,

Chintan

Former Member
0 Kudos
int length_string = a.length();   // a is string to be operated..parameter to UDF

for(i=0; i< (20 - length_string); i++) {

                       a = " "+a;
}
return a;
Former Member
0 Kudos

HI Chintan

What exactly is the requirement you want to achieve using UDF.

Lengths can be fixed at XSD level itself.

In case requirement is to accept the fields of any length but target has fixed lengths then you can use all string operations in UDF.

you can capture length of any field as field.length for strings.

and can trim, find substring etc.

Thanks

Gaurav

Former Member
0 Kudos

What is your scenario??