substring question

beezley

New Member
i know there has to be a simpler way to do this so i wanted to get your thoughts.

I have a field that is 150 chars long. it can be whatever. but on my form i can only write 40 chars of that. so i would like to search for the last space that would fit the 40 then start again on the next line. if there isn't a space then i am just chopping it.

any help would be appreciated.
 
Not sure if I understood your requirement clearly but does this help ?

Code:
[FONT=courier new]DEFINE VARIABLE c150Char AS CHARACTER   NO-UNDO.[/FONT][FONT=courier new]
DEFINE VARIABLE c40Char  AS CHARACTER   NO-UNDO.[/FONT][FONT=courier new]
DEFINE VARIABLE cTemp    AS CHARACTER   NO-UNDO.[/FONT][FONT=courier new]
 
ASSIGN c150Char = "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890".[/FONT][FONT=courier new]
 
DO WHILE LENGTH(c150Char) > 0 :[/FONT][FONT=courier new]
 
    ASSIGN [/FONT][FONT=courier new]
        cTemp    = SUBSTRING(c150Char,1,40)[/FONT][FONT=courier new]
        c40Char  = IF c40Char = '' THEN cTemp ELSE c40Char + CHR(10) + cTemp[/FONT][FONT=courier new]
        c150Char = SUBSTRING(c150Char, (LENGTH(c40Char) + 1)).[/FONT][FONT=courier new]
END.[/FONT][FONT=courier new]
 
MESSAGE c40Char[/FONT][FONT=courier new]
    VIEW-AS ALERT-BOX INFO BUTTONS OK.[/FONT][FONT=courier new]
[/FONT]
 
Back
Top