Home » SQL & PL/SQL » SQL & PL/SQL » writing text on new lines
writing text on new lines [message #248753] Sun, 01 July 2007 11:05 Go to next message
apuw
Messages: 13
Registered: June 2007
Junior Member
Hi
I have a wraptext procedure which accepts input text and fits it within given output length .
Following is my test script

Accept line Prompt 'enter text : '
Accept len prompt 'enter length of output text '
/
DECLARE

loc_text VARCHAR2 (2000) := &line ;
text_out varchar2(1000);

loc_line_length INTEGER := &len;
loc_lines INTEGER;

BEGIN
/* Display a header containing the text and ruler. */
DBMS_OUTPUT.PUT_LINE ('====================');
DBMS_OUTPUT.PUT_LINE (loc_text);
DBMS_OUTPUT.put_LINE (RPAD('1',length(loc_text),'2345678901'));
DBMS_OUTPUT.PUT_LINE
('Wrapping to: '||TO_CHAR(loc_line_length)||' characters.');
DBMS_OUTPUT.PUT_LINE('====================');

wrapt(loc_text, loc_line_length, text_out, loc_lines);
DBMS_OUTPUT.PUT_LINE('====================');
END;
/
ENtertext ' This is a very long line of text which we will wrap to smaller
length : 10
For which I get output showing how text should be divided
====================
This is a very long line of text which we will wrap to smaller 12345678901234567890123456789012345678901234567890 Wrapping to: 10 characters.
====================

What should I write in test script to get the following desired output (text broken (without breaking words apart)with given output length on new lines...
This is a
very long
line of
text which
.........
Re: writing text on new lines [message #248756 is a reply to message #248753] Sun, 01 July 2007 11:37 Go to previous message
Michel Cadot
Messages: 64103
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
The algorithm is, assuming you want you break at N characters, go to the Nth character, if it is a space (or a tab, or a new line...) then output this N characters.
Otherwise go backward till you find a space (or...) and then output till this character.
And continue with the next N characters till the end.

Regards
Michel
Previous Topic: Murging with excel
Next Topic: Raising exceptions
Goto Forum:
  


Current Time: Sun Dec 04 02:23:33 CST 2016

Total time taken to generate the page: 0.11851 seconds