Subject Re: STUFF() returns incorrect character
From Akshat Kapoor <akshat.kapoor@kapoorsons.in>
Date Mon, 4 Jan 2021 18:52:07 +0530
Newsgroups dbase.getting-started

Good Evening John,> Here's the code for the test file. (TestOut.log is
just for troubleshooting) I normally use an .h file, but this was a
quick proof of concept test. In this version, I was testing CHR(00), but
I have tried "", '' and CHR(00):
>
> mchaptest = FOPEN("Test.html","R")
> mtestout  = FCREATE("TestOut.txt","W")
> mchaplog  = FCREATE("TestOut.log","W")
>
> DO WHILE .NOT. FEOF(mchaptest)
>    mstring = FGETS(mchaptest)
>    moutstr = "Current string: " + mstring
>    FWRITE(mchaplog,moutstr)
>    FWRITE(mchaplog,CHR(10)+CHR(13))
>
>    DO WHILE CHR(194) $ mstring
>      moutstr = "Testing for CHR(194)"
>      FWRITE(mchaplog,moutstr)
>      FWRITE(mchaplog,CHR(10)+CHR(13))
>      mpos = AT(CHR(194), mstring)
>      mstring = STUFF(mstring,mpos,1,CHR(00))
>    ENDDO
>
>    DO WHILE CHR(195) $ mstring
>      moutstr = "Testing for CHR(195)"
>      FWRITE(mchaplog,moutstr)
>      FWRITE(mchaplog,CHR(10)+CHR(13))
>      mpos = AT(CHR(195), mstring)
>      mstring = STUFF(mstring,mpos,1,CHR(00))
>    ENDDO
>
>    * write the results
>    FWRITE(mtestout,mstring)
>    FWRITE(mtestout,CHR(10)+CHR(13))
> ENDDO
>
> * close Chapters file
> FCLOSE(mchaptest)
> FCLOSE(mtestout)
>
> Here are sample lines subject to STUFF() and the output:
> </span>В <span style="font-size: 13pt">FebruaryВ 13,В 2020.
> This produces:
> </span> ‚  <span style="font-size: 13pt">February ‚  13, ‚  2020.

Having a look at the code does not give any idea of the error. I agree
with Mervyn that without the actual html page it is damn difficult to debug.

Before sending the file please do not open it in notepad or any other
editor as saving changes could change some characters.

It would be interesting to view the source file in an hex editor
especially near locations where this error is occurring.

There are some special non visible characters that are causing the error
and to locate those we need hex viewer/ hex editor.

Another way to zero in on the error would be to examine the log file you
are creating.

You are deleting 2 characters, do they occur adjacent to each other or
separately. Even if they occur separately why not change them in a
single loop. Why use 2 loops.

Please find pasted below the code I use to convert tabs chr(9) to comma
       fout = new file()
       fin = new file()
       in_file = getfile("AGL_0001.txt")
       fin.open(in_file)
       fout.create("attendance.csv")
          do while not fin.eof()
             chr_str = fin.readln()
             do while at(chr(9),chr_str) >0
                chr_str = stuff(chr_str,at(chr(9),chr_str),1,",")
             enddo
             fout.writeln(chr_str)
          enddo
          fin.close()
          fout.close()

Give the above code a trial.

Regards
Akshat