string search and replace

freak

Member
I need to convert a path and filename on windows platform such as "c:\junk\test.txt" to "c:\\junk\\test.txt". (This is because I am passing it to gnuplot which requires it that way) Anyway... I cannot find a way to search and replace. Here is what I tried and Progress doesn't like it...

DEF VAR s1 AS CHAR INIT 'c:\junk\test.txt'.
DEF VAR c AS INTEGER.
DO c= 1 TO LENGTH(s1):
IF SUBSTRING(s1,c,1) = '\' THEN
SUBSTRING(s1,c,1,"CHARACTER")="\\".
END.


Any tips?
 
try

DEF VAR s1 AS CHAR INIT 'c:\junk\test.txt'.

s1 = replace(s1,'\','\\).

-Parul.


Ok... That was easy. It wasn't because I didn't look though. The help links for substring, overlay, entry, and index never refer to replace in the "SEE ALSO" section and I wasn't smart enough to search for "replace".:awink: Thanks!
 
Please try the following for a replace
DEF VAR s1 AS CHAR INIT 'c:\junk\test.txt' FORMAT "x(20)".
S1 = REPLACE (s1,'\','\\').
Disp S1

Regards
Philip P Oommen



I need to convert a path and filename on windows platform such as "c:\junk\test.txt" to "c:\\junk\\test.txt". (This is because I am passing it to gnuplot which requires it that way) Anyway... I cannot find a way to search and replace. Here is what I tried and Progress doesn't like it...

DEF VAR s1 AS CHAR INIT 'c:\junk\test.txt'.
DEF VAR c AS INTEGER.
DO c= 1 TO LENGTH(s1):
IF SUBSTRING(s1,c,1) = '\' THEN
SUBSTRING(s1,c,1,"CHARACTER")="\\".
END.


Any tips?
 
Back
Top