Page 1 of 1

Find and replace non printable character

Posted: Fri Mar 20, 2020 7:42 am
by RPC
Hi
I need to process a text file. There are comma delimiters in the line but the line itself ends with Line Feed(chr(10)).
I therefore cannot use hb_atokens() effectively. I am enclosing my text file.
I am trying to use following code

Code: Select all

#define LF chr(10)
cString := hb_memoread ("FOVOLT_03032020.csv")
if LF $ cString 
   msginfo (" Found LF ")   // shows message
   strtran(cString, LF, ',')  // doesn't replace
endif
Can someone help please ?
Thanks

Re: Find and replace non printable character

Posted: Fri Mar 20, 2020 7:55 am
by serge_girard
I suggest to read in line by line!

Code: Select all

#define LF chr(10)
cFILE := 'FOVOLT.TXT'
oFile2 := TFileRead():New(cFILE )
oFile2:Open()
IF oFile2:Error()
   MSGINFO ( STR(oFile2:ErrorNo()) + ' ' + oFile2:ErrorMsg( "File open error" ), 'NOK')
   RETURN ''
ENDIF

 
DO WHILE oFile2:MoreToRead()


   cString := ALLTRIM(oFile2:ReadLine())
   cString := strtran(cString, LF, ',')   
   ? cString 
  
ENDDO
oFile2:Close()

BUT THIS MAYBE THE CAUSE:

Code: Select all

strtran(cString, LF, ',')  // doesn't replace
Serge

Re: Find and replace non printable character

Posted: Fri Mar 20, 2020 8:07 am
by RPC
Hi serge_girard
That was lightning quick response.
I will just check it in sometime.
Many thanks
Rajeev

Re: Find and replace non printable character

Posted: Fri Mar 20, 2020 8:08 am
by serge_girard
Yes, you were very lucky...!

Serge

Re: Find and replace non printable character

Posted: Fri Mar 20, 2020 12:19 pm
by RPC
serge_girard wrote: Fri Mar 20, 2020 8:08 am Yes, you were very lucky...
Hi Serge
You are right I am very lucky, you saw my problem and instantly provided solution.
What an elegant solution it is.
I was troubled by text processing for so many days and now I find text processing so easy.
Many many thanks. :D
Rajeev