on 06-23-2010 11:40 AM
Hi all,
If input is char take fist 4 char ( left alligned),
if input is numeric then , right alligned with leading zeroes.
how to get it..
regards,
ramesh.
Hi
Try this:
for(int i=0;i<args[0].length();i++)
{
if(Character.isDigit(args[0].charAt(i)))
{
args[0];
}
else
{
args[0];
}
}
Create two Fix Values:
One: If the output of above function is "A Number", the pass the actual value's length to FIX VALUES.
Key is the length & Value is the space; Eg: If length is 1, then give 9 spaces in FIX values.
Key Value
1 9 spaces
2 8 spaces
3 7 spaces
Concatenate the output of the FIX Values with actual value at the end or start as per ur requirement.
Similarly for "NOT A NUMBER" too.
-
Srikanth Srinivasan
Edited by: Srikanth Srinivasan on Jun 24, 2010 3:31 PM
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Create a UDF with one 'input' parameter
try
{
Integer.parseInt(input );
NumberFormat formatter = new DecimalFormat("000000");
String s= formatter.format(Double.parseDouble(input));
return s ;
}
catch(Exception e)
{
return input.substring(0,4);
}
I have tested the above code..while creating the UDF add the following import to the UDF
java.text.DecimalFormat
java.text.NumberFormat
changed the Decimal format according to your requirement in the above code.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
fatima code is not working completly.
**If input is char take fist 4 char ( left alligned), if input is numeric right alligned with leading zeroes. **
it is giving else part correct but, if it is num it's getting failed.
and it is not taking care of alignments..
input is alphanumeric,we need to apply condition on first char.
If first letter is char then only first 4 digits should be taken
if numeric entire value should be taken ( should add leading zeros to complete 10 digits )
regards,
Ramesh.
Edited by: Sreeramoju Ramesh on Jun 24, 2010 3:30 PM
Hi Ramesh,
Take the first character with substring and find whether it is character or integer. If integer then add zeros else take the first 4 characters.
If your input field is material then map like this:
material ---> substring(0,1) --> udf (CheckNumericORString) ---> if else --> your udf will return 0 if first digit is alphabet else it will send the same input. Then if 0 take first 4 characters else pad with 4 zeros using formatnum(0000). Here you may require to add one more if else condition for checking the total length of input field. If the input length is more than 4 every time then you are ok if it comes less than 4 then that if else condition should take care.
UDF CheckNumericORString:
Create a value udf and name it as CheckNumericORString with one argument and name it as input. Then add this code:
Imports: java.*;
int x = 0;
try{
Integer.parseInt(input);
return input; }
catch(NumberFormatException e){
return "0"; }
This will basically return whether the first digit is numeric or character. If numeric same input will return else 0 will return. So after this with if else your issue should be solved.
Regards,
---Satish
Hi Ramesh,
> Input is alphanumeric so we can't use Format number,what else we can do to add it with leading zeros
Create simple type UDF which is having 2 input fields
1. strVal -- Actual input String
2. totStrLen -- Length of the String (like 10 or...)
int inputValLength =strVal.length();
int totStrLength = Integer.parseInt(totStrLen);
String result="";
if(totStrLength > inputValLength)
for (int i=0; i< totStrLength - inputValLength; i++)
result = result +"0";
return result + strVal;
> Leading zeros with right align.
Default this comes to left alignment, if it is integer then obviously it comes to right alignment.
Regards
Ramesh
User | Count |
---|---|
85 | |
10 | |
10 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.