× 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.



Gotta learn to read the problem first.
Brute force (like the MI version): 5 minutes writing, 2.8 seconds running
d theString       s             50                                   
d theResult       s             50                                   
d loopLimit       s             10u 0 inz(100000)                    
d timestp         s               z                                  
d fr              s             10u 0                                
d to              s             10u 0                                
d at              s               *                                  
d chr             s              1a   based(at)                      
                                                                     
c                   time                    timestp                  
c     timestp       dsply     'BUCK'                                 
c                   do        loopLimit                              
C                   eval      theString = '     this is a test      '
C     ' '           check     theString     fr                       
C     ' '           checkr    theString     to                       
C                   eval      theResult = theString                  
 * prime the translate loop                                          
C                   eval      at = %addr(theResult) + fr - 1         
C     fr            do        to                                     
C                   if        chr = ' '                              
C                   eval      chr = '_'                              
C                   endif                          
C                   eval      at = at + 1          
c                   enddo                          
c                   enddo                          
c                   time                    timestp
c     timestp       dsply     'BUCK'               
                                                   
c                   eval      *InLR=*On            

This should perform worse the longer the string gets.  I thought of a
different way; to scan for the blanks.  15 minutes of coding (including
debugging) and 4 seconds to run.  It should scale better for longer strings
though.

d theString       s             50                                    
d theResult       s             50                                    
d loopLimit       s             10u 0 inz(100000)                     
d timestp         s               z                                   
d fr              s             10u 0                                 
d to              s             10u 0                                 
d i               s             10u 0                                 
                                                                      
c                   time                    timestp                   
c     timestp       dsply     'BUCK'                                  
c                   do        loopLimit                               
C                   eval      theString = '     this is a test      ' 
C     ' '           check     theString     fr                        
C     ' '           checkr    theString     to                        
C                   eval      theResult = theString                   
C                   eval      i = fr                                  
                                                                      
C                   dow       i <= to                                 
C                   eval      i = %scan(' ': theResult: i)            
c                   if        i = 0 or                                
c                               i > to                                
c                   leave                                  
C                   endif                                  
c*                                                         
C                   eval      %subst(theResult: i: 1) = '_'
C                   eval      i = i + 1                    
c                   enddo                                  
                                                           
c                   enddo                                  
                                                           
c                   time                    timestp        
c     timestp       dsply     'BUCK'                       
                                                           
c                   eval      *InLR=*On                    

Buck 

> -----Original Message-----
> From: Leif Svalgaard 
> Sent: Monday, March 19, 2001 11:45 AM
> To:   MIDRANGE-L@midrange.com
> Subject:      Re: Web apps on the AS/400
> 
> you got it backwards. The original string does not have underscores
> in it, but embedded spaces...
+---
| This is the Midrange System Mailing List!
| To submit a new message, send your mail to MIDRANGE-L@midrange.com.
| To subscribe to this list send email to MIDRANGE-L-SUB@midrange.com.
| To unsubscribe from this list send email to MIDRANGE-L-UNSUB@midrange.com.
| Questions should be directed to the list owner/operator: david@midrange.com
+---

As an Amazon Associate we earn from qualifying purchases.

This thread ...


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.