removing an entry from a list

whwar9739

Member
Anyone have some quick way to completely remove an entry in a list including the delimiter?

For example:

list = "1,2,3,4,5,6,7"

I would like to remove 5 and the comma after it giving me the following result

list = "1,2,3,4,6,7"

The list is a list of userid's that have access to a particular program and basically I would like to remove a specific user from having access to a program.
 
Code:
DEFINE VARIABLE list AS CHARACTER   NO-UNDO.
DEFINE VARIABLE iTmp AS INTEGER     NO-UNDO.
DEFINE VARIABLE TmpList AS CHARACTER   NO-UNDO.
DEFINE VARIABLE cRemove AS CHARACTER   NO-UNDO.
ASSIGN list = "1,2,3,4,5,6,7"
       cRemove = "5".
MESSAGE REPLACE(list,'5,','')
    VIEW-AS ALERT-BOX INFO BUTTONS OK.  /*   :-)  */
 
DO iTmp = 1 TO NUM-ENTRIES(list):
  IF entry(iTmp,list) <> cRemove THEN Tmplist = Tmplist + ENTRY(iTmp,list) + ','.
END.
ASSIGN tmpList = TRIM(Tmplist,',')
       list = Tmplist.
MESSAGE list
    VIEW-AS ALERT-BOX INFO BUTTONS OK.

Casper.
 
this won't work if the list has same values or even if the list has:
"1,2,3,5,25,1,35,4"
after executing
list = REPLACE (list,"5,","").
the list will be:
"1,2,3,21,34.

The best way would be:
Code:
entry(3, list) = "".
list = replace(list, ",,", ",").
but it only works when there are no empty string values in the list
 
I had already anticipated something like that.

Instead I did something along the following line:
l-list = replace(l-list,",5,",",").

It has a lot of extra commas but it would ensure that the full entry was 5 rather than just the end of the entry.
 
I'm was 3 minutes faster than "Casper" for this response ...
I'm the best :))
Well at least the fastest :D
And btw I am a bit confused with the last few posts..:confused:
I thought it was obvious that the replace option wouldn't work, therefore my commented ':)' in my code example.

Casper.
 
Back
Top