Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Tom Rettigs Library - wrap(<expc>, <n maximum length>) http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 WRAP(<expC>, <N maximum length>)
 Breaks a long string for output within a specified line length.
 Returns <expN> position of last blank space before <maximum length>.

 <expC> is the string to wrap during output.
 <max length> is the maximum length of output line.

 Returns LEN(<expC>) if <expC> is shorter than <max len>.

 Returns <max len> if a single word with no place to break is
         longer than <max length>.  This will break the word
         and wrap it without hyphenation.

 * Set up following examples
 max_len = 25   && specified line length
 long_exp = <long character expression to display>
 end = LEN( long_exp )
 i = 1

 * Display a long expression within 25 columns
 DO WHILE i < end
    wrap_pos = WRAP(SUBSTR(long_exp,i,i+max_len), max_len)
    ? SUBSTR( long_exp, i, wrap_pos )
    i = i + wrap_pos + 1
 ENDDO

 * Page break routine with header and footer
 SET DEVICE TO PRINT
 body_len = <number of lines in body per page>
 DO WHILE i < end
    <print header>
    DO WHILE i < end .AND. PROW() < body_len  && print body
       wrap_pos = WRAP( SUBSTR(long_exp, i, max_len+i), max_len)
       @ PROW()+1, <column> SAY SUBSTR( long_exp, i, wrap_pos )
       i = i + wrap_pos + 1
    ENDDO
    <print footer>
 ENDDO
 SET DEVICE TO SCREEN


             Placed in the Public Domain by Tom Rettig Assoc.

See Also: ATLAST() ATNEXT() FILEREAD() LINES()

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson