× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



On Thu, 23 May 2002, Wills, Mike N. (TC) wrote:

> I need to do some text wrapping and am trying to figure out how to locate
> the last space in the text. We are on V4R5. I know I can do it in a loop, I
> was just wondering if there is already a bif that can do it.

I just want to chime in with the code we use for this kind of thing:

<From file ERA_TEXT_H (which is a /COPY member that defines functions)>
D*
D*  wordwrap
D*    Left justifies and breaks a string into given lengths.
D*
Dwordwrap         PR          1000A
D string                      1000A
D strlen                         4S 0 VALUE
D*

<From file ERA_TEXT (which is compiled into a module/service program and
placed into a binding directory)>
D*
D*  wordwrap
D*    Left justifies and breaks a string into given lengths.
D*
Pwordwrap         B                   EXPORT
Dwordwrap         PI          1000A
D string                      1000A
D strlen                         4S 0 VALUE
D*
Dspaces           S              4S 0 DIM(1000)
C*
C                   clear                   justified      1000
C     ' '           scan      string        spaces
C                   z-add     1             start             4 0
C                   z-add     1             start1            4 0
C                   z-add     1             lastlen           4 0
C                   z-add     strlen        tmplen            4 0
C                   z-add     *zeros        length            4 0
C*
C     1             do        1000          i                 4 0
C*
C     spaces(i)     ifgt      tmplen
C*
C                   if        ((spaces(i) - lastlen) > strlen)
C                   eval      length=spaces(i)-start
C*
C                   else
C                   eval      length=spaces(i-1)-start+1
C                   endif
C*
C                   if        (length > (1000 - start1))
C     1000          sub       start1        length
C                   endif
C*
C     length        subst(p)  string:start  section        1000
C                   eval      %subst(justified:start1:length) = section
C*
C                   if        ((spaces(i) - lastlen) > strlen)
C                   eval      start=spaces(i)+1
C*
C                   else
C                   eval      start=spaces(i-1)+1
C                   endif
C*
C                   eval      tmplen=start+strlen-1
C*
C                   dow       (start1 < start)
C                   add       strlen        start1
C                   enddo
C*
C                   endif
C*
C                   z-add     spaces(i)     lastlen
C                   enddo
C*
C                   return    justified
Pwordwrap         E

<From a program that call wordwrap() wo you can see how it works.  The
variable varchardtl contains a long string that we want to break into
left justified lines>
...
Ddescarray        S             48A   DIM(5)
...
C                   movel(p)  varchardtl    justified      1000
C                   eval      justified=wordwrap(justified:48)
C                   movea     justified     descarray

Each element of descarray can now be moved into a 48 byte field.

James Rich
james@eaerich.com



As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.