cancel
Showing results for 
Search instead for 
Did you mean: 

help with User Defined Function

Former Member
0 Kudos

Hi

I want to code a UDF which comapres an array that contains "X" or empty values,with an array which contains only "X" and return a boolean array with boolean arguments (true/false)

I tried using the exisiting functions but I didnt find something relevant

Thx,Shai

Accepted Solutions (0)

Answers (4)

Answers (4)

claus_wallacher
Active Participant
0 Kudos

Shai,

you don't need an "array" of 'X'. You only need one constant with the value 'X'. The text function equalS will continue to compare the values provided by your array with the constant 'X' and create an output array of true/false accordingly.

Regards,

Claus

henrique_pinto
Active Contributor
0 Kudos

As the guys have said, you won't get an boolean array from an UDF.

The best you could get from an UFD is a string where each char is either 1 or 0, meaning true or false. Your input could also be a string with either X's or whitespaces.

You could do it like:

int i = 0;

String output = "";

while (i < input.length()) {

if (input.charAt(i) == 'X') {

output = output.concat("1");

}

else {

output = output.concat("0");

}

i++;

}

return output;

bhavesh_kantilal
Active Contributor
0 Kudos

Hi,

<i> return a boolean array with boolean arguments (true/false)</i>

AFAIK, an User Defined Function can return only a STRING. It cannot return a Boolean Variable and also cannot return an Array.

Regards,

Bhavesh

Former Member
0 Kudos

the function "constan" returns only 1 value and not array of "X",any other ideas?

Shabarish_Nair
Active Contributor
0 Kudos

Func 1: public void ChkForX(String[] a,ResultList result,Container container){

int flag = 0;

int count = 0;

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

{

if(a<i>equals("X"))

{flag = 0; }

else

{flag = 1;

count = count + 1;

}

}

if(count > 0)

{

result.addValue("1");

}

else

{result.addValue("0");

}

Func 2:

public void ChkSpaces(String[] a,ResultList result,Container container){

int flag = 0;

int count = 0;

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

{

if(a<i>equals(" "))

{flag = 0; }

else

{flag = 1;

count = count + 1;

}

}

if(count > 0)

{

result.addValue("2");

}

else

{result.addValue("3");

}

Kinda use both these functions with the same input then further build your logic ... but still i dont think you will get a array as output using UDF

claus_wallacher
Active Participant
0 Kudos

Hi Shai,

if I understand your scenario correct you can do that easily with the existing functions. Just use

     Array  
              equalS --> Result
Constant[X] /

Array is the list that contains your input values (X or empty), Result is your target value that will contain true or false. The function equalS will continue to compare the value of Array with the constant X.

Regards,

Claus