Welcome To The Home Of The Visual FoxPro Experts  
home. signup. forum. archives. search. google. articles. downloads. faq. members. weblogs. file info. rss.
 From: tushar Kanvinde
  Where is tushar Kanvinde?
 Kolhapur, Maharastra
 India
 tushar Kanvinde
 To: Alberto Schiappa
  Where is Alberto Schiappa?
 Brescia
 Italy
 Alberto Schiappa
 Tags
Subject: RE: how to correct text efficiently
Thread ID: 248914 Message ID: 248917 # Views: 2 # Ratings: 1
Version: Visual FoxPro 9 SP2 Category: General VFP Topics
Date: Thursday, December 24, 2009 5:31:08 PM         
   


> Hello, I have a 20 Mb file that should be a text file, but for some reasons
> it contains some caracters under 32 (others than chr(13) and chr(10))
>
> I'd like to write some efficient (speed) code that parse the file
> and substitute every single caracter <32 (and not carriage return o linefeed)
> with caracter ' ' (space) with one-to-one correspondence
>
>
> Any ideas ?
>
> I tried something like this (looks terrible I know)
>
>
> numbytes=1024*10
> 
> f2=FCREATE("OUTFILE")
> f1=FOPEN("INFILE")
> 
> IF f1 >0 AND f2>0        
> 	riga=FREAD(f1,numbytes)
> 	
> 	DO WHILE !FEOF(f1)
> 	
> 	  IF AT(CHR(0),riga)>0 OR AT(CHR(1),riga)>0 OR AT(CHR(2),riga)>0 OR ;
> 		AT(CHR(3),riga)>0 OR AT(CHR(4),riga)>0 OR AT(CHR(5),riga)>0 OR ;
> 		AT(CHR(6),riga)>0 OR AT(CHR(7),riga)>0 OR AT(CHR(8),riga)>0 OR ;
> 		AT(CHR(11),riga)>0 OR AT(CHR(12),riga)>0 OR AT(CHR(13),riga)>0 OR ;
> 		AT(CHR(14),riga)>0 OR AT(CHR(15),riga)>0 OR AT(CHR(16),riga)>0 OR ;
> 		AT(CHR(17),riga)>0 OR AT(CHR(18),riga)>0 OR AT(CHR(19),riga)>0 OR ;
> 		AT(CHR(20),riga)>0 OR AT(CHR(21),riga)>0 OR AT(CHR(22),riga)>0 OR ;
> 		AT(CHR(23),riga)>0 OR AT(CHR(24),riga)>0 OR AT(CHR(25),riga)>0 OR ;
> 		AT(CHR(26),riga)>0 OR AT(CHR(27),riga)>0 OR AT(CHR(28),riga)>0 OR ;
> 		AT(CHR(29),riga)>0 OR AT(CHR(30),riga)>0 OR AT(CHR(31),riga)>0
> 		    
> 		    .....
> 
> 		*FWRITE(f2,STUFF(riga,AT(CHR(9),riga),1,' '))
> 	   ELSE
> 		FWRITE(f2,riga)		
> 	   ENDIF
> 		
> 	
> 		riga=FREAD(f1,numbytes)
> 	ENDDO                    
> 
> 	IF LEN(riga)>0           
> 		FWRITE(f2,riga)		     
> 	ENDIF                    
> 

>
>
> Thank's in advance and merry christmas

You can use FILETOSTR, STRTOFILE and CHRTRAN functions

lcStr=''
FOR lnCounter=1 to 31
   IF lnCounter<>10 and lnCounter=13
      lcStr=lcStr+chr(lnCounter)
   ENDIF
ENDFOR
STRTOFILE(CHRTRAN(FILETOSTR("InFile"),lcStr,space(len(lcStr))),"OutFile")


Regards
Tushar

ENTIRE THREAD

how to correct text efficiently Posted by Alberto Schiappa @ 12/24/2009 5:19:08 PM
RE: how to correct text efficiently Posted by tushar @ 12/24/2009 5:31:08 PM
RE: how to correct text efficiently Posted by Alberto Schiappa @ 12/24/2009 5:47:02 PM