cancel
Showing results for 
Search instead for 
Did you mean: 

UDF for finding a string

Former Member
0 Kudos

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!

Accepted Solutions (1)

Accepted Solutions (1)

markangelo_dihiansan
Active Contributor
0 Kudos

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

Answers (2)

Answers (2)

siddhesh_pathak4
Contributor
0 Kudos

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

Former Member
0 Kudos

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