cancel
Showing results for 
Search instead for 
Did you mean: 

String function EndsWith and Concat UDF question

Former Member
0 Kudos

Hi folks,

i have a requirement, for a particular field that i get from sap, i need to check if it ends with - if yea then i need to put it in fron of the field and send to target.

now 1st approach would be to use the string function...ENDSWITH and CONCAT.....from the standard PI function library...

now i dont want to use this approach as the field i am talking about already goes through a lot of conditions and complex mapping to be finally populated and determined....now if i use a combination of ENDSWITH & CONCAT then i thnk il only b puttin on more over head...

instead i am trying to write a udf....something like this...

for(i=0 to a.length,i++)

if(a<i>.endsWith("-")){

String temp = a<i>.replace("-","");

Temp2= "-" concat (temp);

result.addValue(temp2);

this is the logic i want to follow, can someone lead me to an efficient coding?

Thanks,

Hank

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

UDF


public String getOutput(String a,Container container)
//Add this code
if(a.endsWith("-"))
{
int b = a.indexOf("-");
String c = a.substring(0,b);
return "-"+ c;
}
else
return a;

Former Member
0 Kudos

Thank you very much every one...

got the solution....

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi Jovani,

It's simple to achieve using graphical mapping, but you said, already lot of conditions implemented in mapping. So, you will decide for your need. Anyway you can write the UDF as follows,

Create a UDF with one argument 'a'



 if(a.endsWith("-"))
{
a = a.substring(0,a.length()-1);
return "-".concat(a);
}
else
return a;

If the Sting value have ends with "-", put that "-" symbol to infront of the string. Otherwise pass to target as it is.

Hope it will wok fine and simple code also.

Regards

Vijaykumar

Former Member
0 Kudos

Jovani,

Anyways if you want a udf you can write this:

Create a value udf with one input argument 'a' and name it as replaceminus. Add this code:

Imports: java.;*

public String replaceminus(String a,Container container)

//Add this code

if(a.endsWith("-"))

{int b = a.indexOf("-");

String c = a.substring(0,b);

return c;}

else

return a;

So if your input is abc- your output will be abc and if your input is abc then your outupt will also be abc.

Regards,

---Satish

Former Member
0 Kudos

Jovani,

If you consider of performance then standard functions with endwith and replace and concat only will be much better when compared to the UDF. Even you have complex logic please go with standard functions for higher thoroughput. If you want a udf I can give that also.

Regards,

---Satish