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



RPG: Code time: 5 minutes.  Run time: 1.5 sec.  Same 620 environment as
before.  I used a different approach <grin>  This works for the empty string
too.

d theString       s             50    inz('     this_is_a_test      ')
d theResult       s             50                   
d loopLimit       s             10u 0 inz(100000)    
d timestp         s               z                  
                                                     
c                   time                    timestp  
c     timestp       dsply     'BUCK'                 
c                   do        loopLimit              
C     ' ':x'fe'     xlate     theString     theResult
C     '_':' '       xlate     theResult     theResult
C     x'fe':' '     xlate     theResult     theResult
c                   enddo                            
c                   time                    timestp  
c     timestp       dsply     'BUCK'                 
                                                     
c                   eval      *InLR=*On              

Buck 

> -----Original Message-----
> From: Leif Svalgaard 
> Sent: Monday, March 19, 2001 10:04 AM
> To:   MIDRANGE-L@midrange.com
> Subject:      Re: Web apps on the AS/400
> 
> From: Leif Svalgaard <leif@leif.org>
> To: <MIDRANGE-L@midrange.com>
> Sent: Monday, March 19, 2001 8:16 AM
> Subject: Re: Web apps on the AS/400
> 
> 
> > maybe RPG isn't so bad after all  :-)
> > Here is another string problem:
> > 
> > Given a string char(50), replace all
> > EMBEDDED spaces with hyphens,
> > but leave leading and trailing spaces alone.
> > E.g. "     this is a test      "
> > should become   "     this_is_a_test      "
> > :
> 
> solution in MI:
> 
> time to write: 3 min
> time to run (100000 times) 2.4 secs. on 150 box
> code:
> 
> DCL DD THE-STRING  CHAR(50);
> DCL DD THE-RESULT  CHAR(50);
> DCL DD SIZE  BIN(2);
> DCL DD START BIN(2);
> DCL DD END   BIN(2);
> DCL DD NBR   BIN(4);
>     CPYBLAP     THE-STRING, "     THIS IS A TEST      ", " ";
>     CPYBLAP     THE-RESULT, " ", " ";
>     CPYNV       NBR, 100000;
> AGAIN:
>     TRIML       END,   THE-STRING, " ";
>     VERIFY      START, THE-STRING, " ";
>     SUBN        SIZE, END, START;
>     ADDN(S)     SIZE, 1;
>     XLATE       THE-RESULT(START:SIZE),THE-STRING(START:SIZE)," ","_";
>     SUBN(SB)    NBR, 1/POS(AGAIN);
> 
>     RTX      *;
> 
> one little complication (that you are allowed to ignore too) is
> if the string is empty, then the above code fails, but let's
> change the specs to say that you only invoke the code if
> you know that the string is not empty.
+---
| 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-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.