cancel
Showing results for 
Search instead for 
Did you mean: 

Java Code Required

Former Member
0 Kudos

Hi All,

Can you please help me out in this.

I need to write a UDF

1. Check if any perficular field is balnk then return a hypen ( -)

or Check if any that fields contains any leading zeros then also return a hypen .

Ex:

Field = Name

Length = 40

If there is no data provided in the name fields then i will populate ( - )

if there is a single zeros i will return ( - )

If there are multiple zeros then also i need to return ( - ).

I will be glad for the help.

Thanks,

Jay

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

here a sample on i have written :

int i;

int counter = 0;

for( i = 0; i< a.length;i++)

{

if a<i>.equal( " ")

counter = counter +1;

}

if counter > 0

result.addvalue( "-");

shweta_walaskar2
Contributor
0 Kudos

Hi Jay,

Please see if this is of any help:

String s = "0000010";

boolean flag = false;

for(int i=0;i<s.length();i++)

{

if(!s.substring(i,i+1).equals("0"))

flag = true;

if(flag == true){

return s;

break;

}

}

return "-";

Regards,

Shweta

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi Shweta,

Many thanks for the logic.

Yes it works.

-


String s = a;

boolean flag = false;

for(int i=0;i<s.length();i++)

{

if(!s.substring(i,i+1).equals("0"))

flag = true;

if(flag == true)

{

return s;

// break;

}

}

return "-";

-


Point Rewarded.

Best Regards,

Jay

Former Member
0 Kudos

Thanks Partick for the quick reply.

However, here i want to check the total field to be zeros not only the starting string. suppose say the name may start with 00000000ABC00000(length is different , this is just an example) then here i have to pass as it is not hypen.

but if i have all the values as zeros or a single value as zeros then i need to pass a hypen .

I can provide another example:

Feild = Business partner

Length = 5

if 00000 then pass ( - )

or if 0000 then pass ( - )

or if 000 then pass ( - )

or if 00 then pass ( - )

or if 0 then pass ( - )

but if 00001 then pass as it is .

Thanks,

Jay.

Former Member
0 Kudos

Hi,

you could do it with standard functions:

if (Name equalsS Constant "" or Name startsWith "0")

then "-"

else Name

Regards

Patrick