Find and replace non printable character

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

Post Reply
RPC
Posts: 304
Joined: Fri Feb 10, 2017 4:12 am
DBs Used: DBF

Find and replace non printable character

Post 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
Attachments
FOVOLT_03032020.zip
(7.1 KiB) Downloaded 106 times
Last edited by RPC on Fri Mar 20, 2020 8:00 am, edited 1 time in total.
User avatar
serge_girard
Posts: 3309
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

Re: Find and replace non printable character

Post 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
There's nothing you can do that can't be done...
RPC
Posts: 304
Joined: Fri Feb 10, 2017 4:12 am
DBs Used: DBF

Re: Find and replace non printable character

Post by RPC »

Hi serge_girard
That was lightning quick response.
I will just check it in sometime.
Many thanks
Rajeev
User avatar
serge_girard
Posts: 3309
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

Re: Find and replace non printable character

Post by serge_girard »

Yes, you were very lucky...!

Serge
There's nothing you can do that can't be done...
RPC
Posts: 304
Joined: Fri Feb 10, 2017 4:12 am
DBs Used: DBF

Re: Find and replace non printable character

Post 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
Post Reply