× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Hi  y'all,
 
I am trying to find the fastest way to go through a text IFS file and
replace all occurrences of a string. The file sizes that I am working with
range from less then 200 bytes to over 80Kb. Obviously the 80Kb one is
causing the slowness problems that I want to try and remedy.  
 
Below is what I am doing essentially. It only takes two reads from the IFS
file to get all of the data, but I was wondering if there is any way to do a
find and replace faster on that large of a string (65535 varying)?
 
 
 
     P Http_conv       b                   export
     D Http_conv       pi
     D  pFile                       256a   value varying
 
     D error           ds                  likeds(Error_simple)
     D handle          s             10i 0
     D tempFile        s            256a   varying
     D tempHandle      s             10i 0 
     D data            s          60000a   
     D bytesRead       s             10i 0 
     D rc              s             10i 0
      /free
 
       tempFile =pFile + '.temp'; 
       tempHandle = IFS_openFile(tempFile:'CP RW T': ascii);
     
       handle = IFS_openFile(pFile: 'R': ascii);
 
       bytesRead = read(handle: %addr(data): 60000); 
       dow bytesRead > 0;
         data = Util_findReplace(data: '&lt;': '<');
         data = Util_findReplace(data: '&gt;': '>');
         data = Util_findReplace(data: '&quot;': '"');
         data = Util_findReplace(data: '<![CDATA[': '');
         data = Util_findReplace(data: ']]>': '');
         data = Util_findReplace(data: 'xmlns=""': 'xmlns="x"');
         rc = write(tempHandle: %addr(data) :%len(%trimr(data)));
         data = *blanks;
         bytesRead = read(handle: %addr(data): 60000);
       enddo;
 
       //handle =
         //open(
           //pFile: O_RDWR + O_TRUNC+O_TEXTDATA);
       //IFS_writeLine(handle: data);
       rc = close(handle);
       rc = close(tempHandle);
      
       rc = unlink(pFile); 
       IFS_move(tempFile: pFile); 
 
      /end-free
     P                 e 
 
 

     P Util_findReplace...
     P                 b                   export
     D Util_findReplace...
     D                 pi         65535a   varying
     D  pString                   65535a   value varying
     D  pFrom                        30a   value varying
     D  pTo                          30a   value varying
 
     D pos             s             10i 0
      /free
 
       pos = %scan(pFrom: pString);
       dow pos > *zero;
 
         pString = %replace(pTo: pString: pos: %len(pFrom));
 
         pos = %scan(pFrom: pString);
       enddo;
      
       return pString; 
 
      /end-free
     P                 e  

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.