Skip to Content
0

Splitting a long Text into multiple lines.....converting a string into a String Array

Feb 28 at 02:16 AM

26

avatar image

Hi Folks,

I am trying to achieve the below logic in SAP PO but I am having hard time converting String into a String Array. I am a bit confused whether I should use single values or values by queue. If I use single value I am not able to return a string array, but if I use queue values in the UDF I am not able to split the string using the substring. Please suggest.

String s = "The quick fox jumped over a lazy dog";
 
char[] sAr = s.toCharArray();
int start = 0;
        // start with 
for (int i = 13; i < sAr.length; i++) {
    if (sAr[i] == ' ') {
        System.out.println(s.substring(start, i));
        start = i+1;
        i += 13;
    }
}
System.out.println(s.substring(start));

The result of the above code is the following.

The quick fox

jumped over a

lazy dog

The purpose of achieving this is to eventually apply this logic to my PO mapping where in I have to split the long text which exceeds more than 135 characters into the Text line of multiple segment occurrences.

as

E1EDPTEXT [1]

Text line .......first 135 characters

E1EPDTEXT [2]

Text line .......second 135 characters

so and so one

....

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

1 Answer

Best Answer
kalyan golla Feb 28 at 04:09 AM
0

I am able to figure it out. Thanks

public void SplitTextLineActual(String[] textLine, int limitLength, ResultList result, Container container) throws StreamTransformationException{

String stest  = textLine[0];


char[] sArray = stest.toCharArray();
int start = 0;
        // start with 
for (int i = limitLength; i < sArray.length; i++) {
    if (sArray[i] == ' ') {
        result.addValue(stest.substring(start,i));
        start = i+1;
        i += limitLength;
    }
}
result.addValue(stest.substring(start));

}
Share
10 |10000 characters needed characters left characters exceeded