add char to each line in a variable

freak

Member
I have a character variable which contains data as follows...

Joe
Bill
Gary
Mike

There is a carriage return/line feed after each name. Now I need to take the variable and add a character to the beginning of each line so that it will be:

X Joe
X Bill
X Gary
X Mike

I can think of ways to do this but they are messy. Does anyone have a slick method?
 

vinod_home

Member
if its in a variable, can you not do that when assigning the value to the variable. what are you exactly trying to do after you add a character.
 

freak

Member
It is a list of file names passed back from procedure. I need to add "put " in front of each file name to configure a script for an ftp upload.
 

vinod_home

Member
when you create the ftp script, just read this variable for each entry/line and format it anyway you like it. That way if in future you want to add validation to validate if the file exists, you can add it to that same logic. You can also validate if any line is blank with just a carriage return.

HTH
 

freak

Member
" just read this variable for each entry/line and format it anyway you like it."

That's the part I'm having trouble with.
 

freak

Member
Here is what I am doing.
Code:
DEF VAR X AS INTEGER INIT 1 NO-UNDO.
DEF VAR templist AS CHAR INIT '' NO-UNDO.
REPEAT WHILE ENTRY(x,printlist,chr(10))<>'':
    templist=templist + "put " + ENTRY(x,printlist,chr(10)).
    X=X + 1.
END.
printlist=templist.
 

UncleNel

New Member
Here is simple example on how this can be done:

def var cinList as char no-undo.
def var coutList as char no-undo.
def var i as int no-undo.

assign cinlist = "Bill~nDick~nTom~nHarry".

do i = 1 to num-entries(cinList, "~n" /*chr(10)*/):
display entry(i,cinlist,"~n" /*chr(10)*/ ) skip
with 10 down frame a .
down 1 with down frame a.
assign coutList = coutlist +
substitute("&1 &2~n","X",entry(i,cinList,"~n" /*chr(10)*/)) .
display cOutList format "x(40)" with frame b.
pause.
end.
 
Top