string manipulation question

nate100

Member
say if I have the following comma delimited string:

one,two,three,four

I need to have the program extract each element - one two etc..

I was able to do this with the combination of Index and substring but I wanted to ask others what is the best, most efficient way you would go about doing this.
 

montamig

New Member
For example:

DEF VAR i AS INT.
DEF VAR lv-temp AS CHAR.
DEF VAR cad AS CHAR INIT "one,two,three,four".

DEF TEMP-TABLE res FIELD r-field AS CHAR.

i = 1.
REPEAT:
lv-temp = ENTRY(i,cad,",") NO-ERROR.
IF ERROR-STATUS:ERROR THEN
LEAVE.
CREATE res.
ASSIGN r-field = lv-temp
i = i + 1.
END.

FOR EACH res:
DISPLAY r-field.
END.

greetings.
 
Hi there!

Perhaps neater to do this (avoiding REPEAT block and error checking):

DEFINE VARIABLE iLoop AS INTEGER NO-UNDO.
DEFINE VARIABLE cList AS CHARACTER NO-UNDO INITIAL "one,two,three,four".

DO iLoop = 1 TO NUM-ENTRIES(cList):
MESSAGE ENTRY(iLoop,cList)
VIEW-AS ALERT-BOX INFO BUTTONS OK.
END.
 
Top