on 05-15-2012 7:37 PM
Dear All,
I have a quantity field coming in which I am concatenating with date field.
I am checking a condition and then passing quantity to output and concatenate with date else concatenate a constant [space[ with date. My mapping looks like this.
quantity - trim -- if condition true --- concat [ quantity + date ]
else
constant{space} ----- concat [constant + date. ]
After the if else before the concatenate i want to make sure that the space and quantity of same length . For eg if i have quantity coming in as 123.50 for 1st item and no quantity in second item i need to make sure i leave equal number of spaces.
So in the output of the if then else i wrote a UDF below but does not seems to work as intended. Please advice.Thanks !!
int len=input.length();
if(input.length()<15) {
for(int i=0; i<15-len;i++) {
input = input + " " ; }
}
return input;
I want to see result like below.
quantity date concat
123.50 20120508 123.5020120508
[ ] 20120508 20120508
46.50 20120508 46.5020120508
Hi Teresa,
In fact, you don't have to loop over the string and test its length to meet your requirement. Here is the simplest code that will generate the desired output (assuming input is still your input parameter):
String output = String.format("%1$#" + 15 + "s", input);
return output;
Regards,
Greg
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Your screenshot is not very clear to understand. But, I'm trying to understand. You just want UDF for giving spaces for the concat operation. The maximum length for the output string is 15. is that right?
// Use var1 as argument and use the below coding..
for (int count=0; count < 15 - var1.length(); count++){
var1= " " + var1;
}
return var1;
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Trye below UDF,var1 argument
StringBuffer s= new StringBuffer(var1);
int len=s.length();
int spaces=15-len;
for (int i=0;i<spaces;i++)
s.append(" ");
var1 = s.toString();
return var1;
Best Regards,
Raj
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
84 | |
10 | |
10 | |
9 | |
7 | |
6 | |
5 | |
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.