cancel
Showing results for 
Search instead for 
Did you mean: 

substring to get last values

naveen_chichili
Active Contributor
0 Kudos

Dear All,

I have a mapping where I am using an udf for substring in PI 7.3.

I am using below udf code for substring

-----------------

String variable1="";

if (variable1!=null)

   output1 = variable1.substring(6, variable1.length());

return output1;

---------------

if the same udf is used for the other field it is not working...

-------------------
String output1="";

if (output!=null)

   output1 = output.substring(12, output.length());

return output1;

---------------

Also I tried creating function libraries also but no luck..

could any one suggest me...

Thanks and Regards,

Naveen.

Accepted Solutions (0)

Answers (6)

Answers (6)

Former Member
0 Kudos

Hi naveen,

You mean you need a generic udf to use for two of the fields you have mentioned. Is tat your requirement? In tat case pass the numbers 6 and 12 as constants and use the below generic udf.

public String findSubstring(String input, int Count, Container container) throws StreamTransformationException

{

String output="";

if(input!= null)

  output = input.substring(count,input.length());

else

  output="";

return output;

}

former_member184789
Active Contributor
0 Kudos
baskar_gopalakrishnan2
Active Contributor
0 Kudos

This is pretty simple requirement. Please share your code.

@Anupam:  I think it's typo error. You check not null twice in the line 5.

anupam_ghosh2
Active Contributor
0 Kudos

Hi Baskar,

                Thank you for pointing out the typing error. Corrected the same.

Regards

Anupam

anupam_ghosh2
Active Contributor
0 Kudos

Hi Naveen,

                   Made little changes to your code. Please try the code given below

public static String returnStr(String output)
{
  String output1="";
  int l;

  if (output!=null  && !output.equals("") )
  {
     l=output.length();
     if(l>=12)
     {
      output1 = output.substring(12,l);
     }   
    
  }  
  
  return output1;

}

Regards

Anupam

Message was edited by: Anupam Ghosh

0 Kudos

Hello Naveen,

Please check the first UDF, here variable1 is an argument string, please try to change the first code line: String variable1="";  to String output1="";

-----------------

String output1="";

if (variable1!=null)

   output1 = variable1.substring(6, variable1.length());

return output1;

-----------------

Best Regards,

Luis.

Former Member
0 Kudos

Hi.

Can you provide the values for that?

I guees the problem is with the length is less 12.

Regards