on 08-04-2009 8:30 PM
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
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));
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
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
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
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);
}
}
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
93 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.