Skip to Content
Former Member
Oct 26, 2007 at 04:52 PM

example of simple User Defined Function : gives last part of string


I made this function because we needed a modulo operation over a sum of values.

this makes the string containing sum being of variable length. then the substring

operator cannot reliably give me a fixed amount of positions on the end of the string. also, a Modulo operator is missing from XI 3.0 SPS 18.

Thus I needed a UDF. I could not find a decent simple example here (my bad, I'm sure...)

Stilll here ?

Then, open you graphical mapping editor and create a new UDF (see lower left corner),

specify a name and description,

set cache:value,

create two input parameters (input string and string containing the number of position desired).

no further imports of java archives are required.

then enter your code

automatically generated header :

<b>public String LastPos(String instring,String sublength,Container container){</b>

You code in the edit window :

<b> //write your code here

int subintvalue = 0 ;

String myresult = "" ;

subintvalue = Integer.parseInt(sublength,10); // extract number from string

if (subintvalue < 1)

{subintvalue = 0; // do some sanity checking

} ;

if (instring.length() > subintvalue)

{ myresult = instring.substring((instring.length() - subintvalue), instring.length());

} // if the input is large enough, get the last part of the string


{ myresult = instring ; // else just return the whole input string


return myresult ;// put out your truncated string </b>

last generated item :


that's all. now learn java 😉

One small question : I would like to document all created UDF's

how do I find these in a smarter way than reviewing all interfaces and all mappings ?

And is there a way to print/export the UDF including it's settings ?

XI is BAD when it comes to printing any content...

(otherwise I could have shown the usage of the

LastPos udf in a mapping here....)

Hope this helps you when the day comes you will need a UDF.