| Subject |
Re: STUFF() returns incorrect character |
| From |
Gaetano <gaetanodd@hotmail.com> |
| Date |
Sun, 3 Jan 2021 17:00:46 +1000 |
| Newsgroups |
dbase.getting-started |
A Akshat metioned, a few more details would help to understand what is
going on.
A few questions form my side:
1. why use low level functions instead of the file object?
2. from the command line, you only do one line at a time while in the
PRG you would be looping presumably. If AT() doesn't find the character,
it returns 0, how does your code code handle that?
Here is what I use to replace characters. If you want to use read()
instead of gets(), just replace gets() with read(), but don't read more
than 2000 characters at a time, stuff's performacne deteriorates rapidly
with bigger strings :
fIn = new file()
fInput = "whateverFile.txt"
fIn.open(fInput)
fOut = new file()
fOutput = "whateverOutputFile.txt"
fOut.create(fOutput)
do while not fIn.eof()
cStr = fIn.gets()
cStr=strip(cStr,"NaN","0")
fOut.writeln(cStr)
enddo
fIn.close()
fOut.close()
function strip( cArg, cStrip ,cNew)
local cRet, nLen
cRet = cArg
nLen = len( cStrip )
do while cStrip $ cRet
cRet := stuff( cRet, at( cStrip, cRet ), nLen, cNew )
enddo
return cRet
On 03/01/2021 03:53, John Gillen wrote:
> Hello,
>
> I am using low level file functions (FOPEN(), FEOF(), FREAD(), FWRITE() and FCLOSE() to parse a text file. As part of this parsing, I am using three commands to replace characters in the incoming file: mstring = <incoming string>; mpos = AT(<where character to replace is found in the incoming string>); mstring = STUFF(mstring,mpos,1,"") to do the character replacement.
>
> If I run these three steps in the Command window, it works as expected.
>
> If I run these three steps in a program, instead of NULL, I get a comma (,).
>
> I tried "",'', and NULL CHR(0) all with the same result - a comma.
>
> dBASE 8/Windows 10 64bit
>
> Any ideas/suggestions are appreciated.
>
> John
>
|
|