on 03-05-2009 1:36 PM
Hi all,
I'm required to do an UDF to a certain check on the value:
If the string "-" is found in the value i shouldn't modify the value
If the string is not found then i would need to remove any leading 0's of that number => 000000003134 = 3134
The only problem is that i'm not familiar with the java coding required for my UDF (the check for the string and the remove zeros or not)
Could someone help me with this with an example??
Thanks in advance!
Hi,
This can be done without UDF, just follow as what Rajesh has suggested. You will be using the indexOf and ifThenElse functions for this.
Alternatively, you can use this UDF:
UDF type is of queue type:
argument is input
Imports - import java.text.DecimalFormat;
DecimalFormat df = new DecimalFormat("0");
for (int a = 0;a<input.length;a++)
{if (input[a].indexOf("-")>-1){result.addValue(input[a]);}
else {result.addValue(df.format(Double.parseDouble(input[a])));}}
Hope this helps,
Edited by: Mark Dihiansan on Mar 5, 2009 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.
Hello,
You can use the below code. Try out.
if(a.equals("-"))
else
{
char[] chars = str.toCharArray();
int index = 0;
for (; index < str.length(); index++)
{
if (chars[index] != '0')
{
break;
}
return (index == 0) ? str : str.substring(index);
}
}
Edited by: Siddhesh Pathak on Mar 5, 2009 2:51 PM
Edited by: Siddhesh Pathak on Mar 5, 2009 2:52 PM
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
All you need to do is to use indexOf method of s atring if it returns a no other than o then you need to do a copy of your value to target else dont need thats it
Try to start with this you can acheive it no need to depend on somebody for exact code ,we have google
and some udf blogs for kick start
And if you know some basics like class and method enough for this udf
Rajesh
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 | |
23 | |
11 | |
9 | |
8 | |
5 | |
5 | |
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.