on 10-17-2011 11:28 PM
Hi,
If I receive a value as 123,456 and I need to map the integer number to FIELD1 and the decimal number to FIELD2 as this:
FIELD1=123
FIELD2=456
Can I do this without using UDFs?
Hi,
I don't think this is possible with standard text functions, as inputs to substring function are constants. You definitely need an UDF here.
String splitNumber(String s,int part,Container container)
{
String a[]=new String[2];
a[0]=a[1]="";
char decimalSeparetor=',';
try
{
int i=0,j=0,l;
for(l=s.length();i<l && s.charAt(i)!=decimalSeparetor;++i)
{
a[j]=a[j]+s.charAt(i);
}
for(j=1,i=i+1;i<l;++i)
{
a[j]=a[j]+s.charAt(i);
}
}
catch(Exception e)
{
e.printStackTrace();
}
return a[part];
}
The UDF has two inputs as shown below
113,567 -------->splitNumber("113,567",0) ----------> 113 (output)----->FIELD1
113,567--------->splitNumber("113,567",1) ------------> 567 (output)------>FIELD2
113567---------->splitNumber("113567",0)----------------->113567 (output)-------->FIELD1
113567---------->splitNumber("113567",1)-----------------> no output ------>FIELD2
The value of integer part (to be supplied as constants) decides which whether you need the part of number before(0) the decimal separetor or after (1).
regards
Anupam
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks a lot!!! All the UFDs worked!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Yes .. you can use substring(standard function) which suits your requirement....
Regards,
Naveen
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 try using substring standard function
Regards
sandeep
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 try this UDF.
You will declare two parameters one for value and the other for position (0 is for integer value ) (1 for decimal value)
//write your code here
String valSplit[] = Value.split(",");
int position = Integer.parseInt(Pos);
return valSplit[position].toString();
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
87 | |
10 | |
10 | |
10 | |
7 | |
6 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.