cancel
Showing results for 
Search instead for 
Did you mean: 

Creating Multiple Element in the Message mapping using UDF

Former Member
0 Kudos

XI Experts,

I would like to create a UDF in XI-MM for following requirement,

Source - text (String Max length unlimited) - Occurance - 1

Target - text (field Max length 255) - Ocrruance 0 to many

I would like to split the text at every 255 charachter and create a new target text element for the next 255 charachter and so forth... I need your help to write UDF for it.

Help is greatly appreciated.

Thanks!

MP

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi

Please use this code.

Recive Two Parameter .. the Values - inputList and the sizeSplitList[] in this case a Constant "255"




        int targetLen = 0;
        int sourceLen = 0;
        int count = 0;
        int pos = 0;
        for(int i = 0; i < inputList.length; i++)
        {
            if(i < sizeSplitList.length)
                targetLen = Integer.parseInt(sizeSplitList<i>);
            sourceLen = inputList<i>.length();
            count = sourceLen / targetLen;
            for(pos = 0; pos < count * targetLen; pos += targetLen)
                result.addValue(inputList<i>.substring(pos, pos + targetLen));

            if(pos < sourceLen)
                result.addValue(inputList<i>.substring(pos));
        }

Former Member
0 Kudos

Luis,

Thanks you very very much for your quick and correct code...

I am going to give you full marks... but have a little request to give me suggestion or code to do the word wrap.

Thanks again..

MP

Former Member
0 Kudos

Hi MP

Can you explain it more clearly? A word wrap depend some length?

Former Member
0 Kudos

Luis,

I have to warp the word if it is cut off at 255th char..

for e.g There are many flowers in the garden

If 255th char.. is at "r" of garden word then I have to cut the 1st element at "There are many flowers in the" and take "garden" to the next element.

Thanks for your quick response..it is highly appreciated.

MP

Former Member
0 Kudos

Hi Mp

Please try to use the code above and write a UDF function with two parameters (inputList ,sizeSplitList). The function cut the value and create a new element according the length of the second parameter. (constant 255)

Former Member
0 Kudos

Hey Luis,

I got your point and the code you have given is working fine with my expectation but I would like to do the word warp also.. as I explained in my above communication... Do you know the way to achieve this? If yes, it will be great help and if not then I will mark this question as resolve and give you full marks...

Thanks for your help!

MP

Former Member
0 Kudos

Hey

There was a similar question sometime ago and i replied to it with an algorithm to cut/wrap the text.

its not a complete UDF but outlines steps to write it.

You need to check the character at position 255,if it is anything except blank then increase the counter by 1 ,check that character(at 256 position) and if even that is anything except blank then increase the counter again.keep on doing this until you reach a blank.

split your payload from here .

Thanks

Aamir

Edited by: Aamir Suhail on Aug 4, 2009 3:51 PM

Former Member
0 Kudos

hi,

Use this code, pls:


        int maxlen = 10;
        String [] a = {"this is an example how to wrap a phrase"};
        String [] words;
        String cad = "";
        words = a[0].split(" "); ///splitting by blank space
        int index = 0;
        while(a[0].length() > 0){
            for(int x = index ;  x < words.length ; x++){
                if(x != words.length - 1){
                    words[x] += " ";//adding space 
                }
                if( cad.length() + words[x].length() <= maxlen){
                    cad += words[x] ;
                    a[0] = a[0].substring( words[x].length() );
                }else{
                    //delete blank space
                    if(x != words.length - 1){
                        words[x] = words[x].substring(0, words[x].length() - 1);
                    }
                    result.addValue(cad);
                    cad = "";
                    index = x;
                    x = words.length;
                }                
            }
            if(cad.length() != 0){
                result.addValue(cad);
            } 
        }

Former Member
0 Kudos

Hi.. MP

Well My suggestion is verify if the value has an blank space otherwise complete with blanks until the position 255 and create a new element.

Former Member
0 Kudos

Thanks to Luis and Jose...

MP

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi,

Try with this:


int maxlen = 255;
//function scope: context
//a[ ]: input list
for(int i = 0 ; i < a.length ; i++)
    while(a<i>.length() > 0){
            if(a<i>.length()< maxlen ){
                result.addValue(a<i>);
                a<i> = "";
            }else{
                result.addValue(a<i>.substring(0,maxlen ));
                //if you want to put each element in a different context, add:  result.addValue(ResultList.CC);
                a<i> = a<i>.substring(maxlen);
            }
   }
 }

Regards

Ivan