cancel
Showing results for 
Search instead for 
Did you mean: 

Line Break after 132 words in web Dynpro java

Former Member
0 Kudos

Hi,

i want to pass a paragraph in R/3 through web dynpro java, because in r/3 there is restriction it will take 132 character in one row,due to this reason i want restrict in java also.means 132 character in one row, next word in second row.

String textLine = wdContext.currentContextElement().getText();

////                              int length = textLine.length();

//

//                              int currentLength = 0;

//                                                   while(text.length()>0)

//                                                   {

//                                                              currentLength = text.length();

//                                                              if(currentLength > 132)

//                                                              {

//                                                                                String[] lines = textLine.split("132");

//                                                                          text = text.substring(131);

//                                                              }

//                                                              else

//                                                              {

//                                                                         subString = text.substring(0,currentLength);

//                                                                         text = text.substring(currentLength);

//                                                              }

Please help or provide code for the solution.

Regards,

Shashank

Accepted Solutions (0)

Answers (1)

Answers (1)

amolgupta
Active Contributor
0 Kudos

System Independent Newline Characters

There are three different major systems for indicating the end of a line (new line): One for Unix, one for the Macintosh, and one for DOS/Windows.

Unix. The '

' character represents the single Unicode character with the value 10 ('\u000A') and is used to separate lines in Unix files. This character is also sometimes called linefeed.

Windows. Windows programs often process a '

' separated text file correctly (NotePad is a exception), but many expect a pair of characters (carriage return followed by line feed = "

") Use the method below to get the newline string that is appropriate for your system.

Mac. In the past, the Apple Mac requirse lines to be separated by ' ', but their move toward Unix (System X) probably means they also accept '

'. I haven't used a Mac in quite a while tho, so I'm not positive.

System independent value. You can get the value for the system your Java program is running on from the system properties. It is essential to do this with portable programs, and you should always assume your program is portable, eg, that it might run as an applet or using Webstart.

public static String newline = System.getProperty("line.separator");

When NOT to use the system independent newline characters

JTextArea lines should be separated by a single '

' character, not the sequence that is used for file line separators in the operating system.

Console output (eg, System.out.println()), works fine with '

', even on Windows.

http://www.leepoint.net/notes-java/io/10file/sys-indep-newline.html

Placing a System independent line separator should see you through.

I hope this solves your problem.

Regards,

-Amol Gupta

Former Member
0 Kudos

Hi,

but still problem not resolve....

Regards,

Shashank

amolgupta
Active Contributor
0 Kudos

hi Shashank,

To see your Text in WebDynpro Java 132 chars in 1 row you can use a Text Edit UI element with cols property set to 132.

For example, in the below example i have used a Text Edit UI element with cols property set to 10. When i exceed the 10 chars limit, text is sent to next row and so on.

I hope this solves your problem.

Thanks and Regards,

-Amol Gupta

Former Member
0 Kudos

hi,

i already use this, it showed the letter in the portal but in back end their is a database table in R/3 and their is restriction is 132 character in one line only.
it pick up only one line means 132 character and rest drop it.we fetch the data through BAPI.

Regards,

shashank

Former Member
0 Kudos

Shashank, the next code snippet insert new line delimiter into string in each 132 position, does you mean such solution?

        String newLine = System.getProperty("line.separator"); // thanks to Amol
        String textLine = wdContext.currentContextElement().getText();
        StringBuffer buffer = new StringBuffer();
        int startPos = 0;
        
        do {
            if (startPos != 0) {
                buffer.append(newLine);
            }
            int endPos = startPos + 132;
            if (endPos < textLine.length()) {
                buffer.append(textLine.substring(startPos, endPos));
                startPos = endPos;
            } else {
                buffer.append(textLine.substring(startPos));
                break;
            }
        } while (true);

        String result = buffer.toString();