on 09-29-2008 4:05 PM
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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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;
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
What is your scenario??
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
93 | |
11 | |
10 | |
9 | |
9 | |
7 | |
6 | |
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.