Re: Ascii / Text Replacement / Substitution ?
Posted in 1997
I dug up the routines below from the Power-4gl package (see http://www.rl.is/~john/pow4gl.html) which, in your case, should enable you to do: let cData = strrep(cData,"dumb","cool") let cData = strrep(cData,"\\\\r\\\\n","<BR>") ############################################################################## # Replacement of substring within a string with another string. ############################################################################## function strrep(string,str1,str2) define string char(1000), str1,str2 char(100), pos,len1,len2 smallint let len1 = length(string) let len2 = length(str1) let pos = strpos(string,str1) while pos <> 0 let string = substr(string,1,pos-1) ,str2 clipped ,substr(string,pos+len2,len1-(len2+pos-1)) let pos = strpos(string,str1) end while return string end function ############################################################################## # Determination of substring position within a string. ############################################################################## function strpos(str,sub) define str char(1000), sub char(100), i,j,len1,len2 smallint let len2 = length(sub) if len2 > 0 then let len1 = length(str)-len2+1 for i = 1 to len1 if str[i,i] = sub[1,1] then if str[i,i+len2-1] = sub then return i end if end if end for end if return(0) end function ############################################################################## # Retrieval of substring from within a string. ############################################################################## function substr(str,pos,num) define str char(1000), pos,num,len smallint if pos <= 0 or num <= 0 then return "" end if let len = length(str) if pos > len then return("") end if if (pos+num-1) > len then let num = len - pos +1 end if return(str[pos,pos+num-1]) end function Best wishes, ---------------------------------------------------------------------- John H. Frantz Power-4gl: Extending Informix-4gl frantz@centrum.is http://www.rl.is/~john/pow4gl.html In article <3479199D.4906@ccs.net>, jcokos@ccs.net wrote: > > This one should be easy for you pros: > > In 4gl, I just need to replace (Like sed) characters within a string. > Specifically, I need to replace a certain 4 characters with another... > > ie. cData = "Freds Mom is dumb, really dumb" > How do I change cData to "Freds Mom is cool, really cool" > > Or, for a tougher example (The one i'm working on for a CGI project): > cData = "This is line 1\\r\\nThis is line 2\\r\\n\\r\\nThis is line 4" > I need to change that into: > "This is line 1<BR>This is line 2<BR><BR>This is line 4" > > I can insert the "<BR>" into the string fine, but I cant get rid of the > \\r or the \\n > > If possible, Id like to do this in 4gl, not with c > > Thanks in advance -------------------==== Posted via Deja News ====----------------------- http://www.dejanews.com/ Search, Read, Post to Usenet