cancel
Showing results for 
Search instead for 
Did you mean: 

padding string - UDF

former_member200267
Participant
0 Kudos

Hi experts,

I want to create a UDF for padding string in the mapping.

I created the following source code in eclipse:

public static String padLeft(String input, int length, char padChar)

{

if (input.length() >= length)

return input;

StringBuffer sb = new StringBuffer(length);

for (int count = length - input.length(); count > 0; count--)

{

sb.append(padChar);

}

sb.append(input);

return sb.toString();

}

please let me know how to use this code in XI.

step by step procedure is appreaciated.

Regards,

RDS

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

In your desired mapping, create UDF of cache value, with three input parameters

1. input string

2.length - pass it as string and inside UDF convert it into Int

3. padChar

then write your code in editor

mapping would look like

3 parameters --> UDF --> target value

Answers (4)

Answers (4)

GabrielSagaya
Active Contributor
0 Kudos

use simple udf and have 3 input parameters(a,b,c) rename it as input,length,padChar.

function padLeft(String input, String length, String padChar, Container container)

{

int len=Integer.parseInt(length);

if (input.length() >= len)

return input;

StringBuffer sb = new StringBuffer(length);

for (int count = len - input.length(); count > 0; count--)

{

sb.append(padChar);

}

sb.append(input);

return sb.toString();

}

Former Member
0 Kudos

Hi,

The requirement can be achieved in 2 ways.

1) Compile the java file , archive the class file and import that file under imported archives.Go to message mapping and create an UDF by providing the name of the compiled file.

add the output of the function to the resultlist.By approaching in this way, the function can be accessed across the namespace

2) Go to the message mapping and create a new function by providing the number of inputs and replace the return statement by adding value to the resultlist(i.e resultList.addValue).By approaching in this way, the function is accessible in that mapping only.

Thanks,

Kiran

Former Member
0 Kudos

Hi,

The requirement can be achieved in 2 ways.

1) Compile the java file , archive the class file and import that file under imported archives.Go to message mapping and create an UDF by providing the name of the compiled file.

add the output of the function to the resultlist.By approaching in this way, the function can be accessed across the namespace

2) Go to the message mapping and create a new function by providing the number of inputs and replace the return statement by adding value to the resultlist(i.e resultList.addValue).By approaching in this way, the function is accessible in that mapping only.

Thanks,

Kiran

former_member859847
Active Contributor
0 Kudos

Hi,

you want to use the program across software component mean,go through imported arhive.

i mean, complie java program and make it as jar to import as archive.

else, you want to use specific to u r mapping means,

you have an option to create new function.

declare the no.of. inputs and write the code.

warm regards

mahesh.