Skip to Content

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

Feb 28 at 02:16 AM


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;

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.



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


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

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] == ' ') {
        start = i+1;
        i += limitLength;

10 |10000 characters needed characters left characters exceeded