on 08-21-2009 7:57 AM
hi Team,
I have a question i think an UDF must be used for this requirement.
that is.
" Length of this field should be 10 characters. If don't fill with zeros on the left."
Can any one help me in this plz.
Thanks & Regards,
vishnu
Hi Vishnu,
U can use this:
int str_len;
int yes_no = 0;
int count;
char[] b = new char[10];
str_len = a.length();
if (str_len < 10)
{
a.getChars(0,str_len,b, 0);
for (int i=0;i<str_len;i++)
{
if (b<i> != '0' && b<i> != '1' && b<i> != '2' && b<i> != '3' && b<i> != '4' && b<i> != '5' && b<i> != '6' && b<i> != '7' && b<i> != '8' && b<i> != '9')
{
yes_no = 1;
continue;
}
}
if (yes_no != 1)
{
count = 10-str_len;
for (int j=0;j<count;j++)
{
a=0+a;
}
return a;
}
else
return a;
}
else
return a;
Thanks,
Sudhansu
Ps: Provide points for helpful answers
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Vishnu,
I am writing a UDF for this.
String res = "" ;
int LengthString = a.length();
if (!a.equals(""))
res = res + a ;
for(int i=LengthString; i< 10; i++)
{
res = 0+res ;
}
return res;
This will check the length of your source field and insert zeroes whenever the length is less than 10.
regards,
Ramya Shenoy.
note:This udf works..give me points .
Edited by: Ramya Shenoy on Aug 27, 2009 11:19 AM
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Other Option
//write your code here
int vLength = Integer.parseInt(pLength);
String value = "";
if (pValue.length() <= vLength){
int missing = vLength - pValue.length();
for (int i = 0 ; i < missing ; i++)
value+="0";
value=value + pValue;
}else{
value = pValue;
}
return value;
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Vishnu,
If the Input is always number then you can use FormatNum standard function. But input value contains single character, that standard function doesn't support.
So, use this UDF.
for(int i=0;i<10 - a.length();i++)
{
res = res + "0";
}
res = res.concat(a);
return res;
I hope, it will work fine.
regards
Vijaykumar
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi ,
you can achive this using the standard function FORMAT NUM
Regards,
Jude
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Vishnu,
No need of UDF...
Map like this...
input------->formatNumber[0000000000]---->output
provide 10 '0's there..
It will automatcally add 0's on left hand side if that is not having 10 digits...
formatNumber is a standard function in Arthematic functions in Graphical mapping....
Thanks.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
try this..
String outVal = "0000000000" + inVal.trim();
outVal = outVal.substring(inVal.length() - 10);
return outVal
inVal is the input to the UDF.
~SaNv...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
86 | |
10 | |
10 | |
9 | |
7 | |
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.