cancel
Showing results for 
Search instead for 
Did you mean: 

User Defined Function in XI

Former Member
0 Kudos

Dear All,

I have to create a user-defined function that would accept the input value and modify it such that the leadign 0's are truncated.

The input value from the source field can be a integer or alpha numeric.

Please suggest some ways to write the code.

Regards,

Rajendra

Accepted Solutions (0)

Answers (9)

Answers (9)

former_member192295
Active Contributor
0 Kudos

HI,

Develop UDF using below code,

String stringWithoutZeros = a.replaceFirst("^0+", "");

return(stringWithoutZeros);

I hope your problem will be sort out

Former Member
0 Kudos

Hi,

We have used following code in our project for the same thing.

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

{

String body="";

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

{

body=a[j];

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

{

if(body.substring(0,1).equals("0"))

{

body= body.substring(1,body.length());

}

}

result.addValue(body);

}

}

with regards,

Ravi Siddam

Former Member
0 Kudos

Hi,

No need for a UDF. This can be done through graphical mapping even.


Source--------->
                    div(Arithmetic function)---->target
constant[1]--->

Former Member
0 Kudos

Hi,

Try this:

for RemoveLeadingZeros

int value = Integer.parseInt(str);

String str1 = Integer.toString(value) ;

return str1;

Regards,

Nithiyanandam

Former Member
0 Kudos

Hi,

Try this:

public String truncate(String a, Container container)
{
   if (a.length() > 0)
   {
      String b = a.replaceAll("^0*", " ");
      return b;
   }
   else
   {
      return a;
   }
}

source field -> UDF -> target field.

Former Member
0 Kudos

To remove leading zeros

public String removeLeadingZeros(String str) {

if (str == null) {

return null;

}

char[] chars = str.toCharArray();

int index = 0;

for (; index < str.length; index++) {

if (chars[index] != '0') {

break;

}

}

return (index == 0) ? str : str.substring(index);

}

Former Member
0 Kudos

Use arithmetic function 'mul' and multiply the field with 1, it wud remove the leading zeroes.

if it is coming as string - cast it to an integer.

stefan_grube
Active Contributor
0 Kudos

A guy started a Wiki page entry with useful UDF codes:

https://www.sdn.sap.com/irj/sdn/wiki?path=/display/xi/javaFunctionsin+XI

Regards

Stefan

Former Member
0 Kudos

Hi,

Here is the similar topic:

Regards,

Radek