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



Actually, you can't have an ending position at all.  From the ILE RPG 
reference: "%SUBST(string:start{:length})".

Personally, I think it should have been an ending position too, but I 
guess (string:start:length) is intuitive for some and (string:start:end) 
is intuitive to others.

Adam



Michael Shutte wrote on 05/04/2006 09:11:20 AM:

> No, you can't have a negative ending position in the substring function.
> 
> Michael Schutte
> Work 614-492-7419
> email  michael_schutte@xxxxxxxxxxxx
> 
> 
>  
>              "Stiju Easo"  
>              <stiju.as400@gmai  
>              l.com> To 
>              Sent by:                  "RPG programming on the AS400 /  
>              rpg400-l-bounces@         iSeries" <rpg400-l@xxxxxxxxxxxx>  
 
>              midrange.com cc 
>  
> Subject 
>              04/05/2006 09:01          Re: RPGLE pgm to parse a string  
>              AM  
>  
>  
>              Please respond to  
>               RPG programming  
>               on the AS400 /  
>                   iSeries  
>              <rpg400-l@midrang  
>                   e.com>  
>  
>  
> 
> 
> 
> 
> should it be
> 
> if %subst(input:pos:1) = '_';
> 
> or
> if %subst(input:pos:-1) = '_';
> 
> as the methord u said we have to come reversely
>  will rpgle accept -1 in place of integer?
> 
> 
> 
> 
> 
> On 4/5/06, Scott Klement <rpg400-l@xxxxxxxxxxxxxxxx> wrote:
> >
> > Hello,
> >
> > > Its not in flat file,Its is a field
> > > My field may have varible no of '_'
> > > i want to extract values b/w second last '_' and third last '_'.
> > > i want to store this details in same database as a field
> >
> > I'm sorry if someone has already answered your question.  I've read 
the
> > thread over, but I'm somewhat confused by whether this was resolved or
> > not.
> >
> > What I'd do is write a loop that searches for the underscore 
character.
> > Something like this:
> >
> >      len = %len(Input);
> >      count = 0;
> >
> >      For pos = len downto 1;
> >          if %subst(input:pos:1) = '_';
> >              count = count + 1;
> >              select;
> >              when (count = 2);
> >                 endpos = pos - 1;
> >              when (count = 3);
> >                 startpos = pos + 1;
> >                 leave;
> >              endsl;
> >          endif;
> >      endfor;
> >
> >      if ( count < 3 );
> >         // error -- not enough underscores found!
> >         data = '';
> >      else;
> >         len = (endpos - startpos) + 1;
> >         data = %subst(Input: startpos: len);
> >      endif;
> >
> > I didn't compile or test this code, but it should give you the basic
> idea.
> > This is what it does:
> >
> >    a) Find out how long the string is.
> >    b) Loop from the last position to the first position
> >    c) Count each '_' char.
> >    d) Save the 2nd & 3rd ones from the end.
> >    e) If they were found, extract the data between them.
> >
> > Pretty simple, really.  There's no need to reverse the characters in 
the
> > string, doing so would only require additional CPU time.  Though,
> > reversing the characters would be easy enough to do just by looping 
from
> > the end to the start and concatenating each character to a new string.
> >
> > Anyway, good luck.
> >
> > --
> > This is the RPG programming on the AS400 / iSeries (RPG400-L) mailing
> list
> > To post a message email: RPG400-L@xxxxxxxxxxxx
> > To subscribe, unsubscribe, or change list options,
> > visit: http://lists.midrange.com/mailman/listinfo/rpg400-l
> > or email: RPG400-L-request@xxxxxxxxxxxx
> > Before posting, please take a moment to review the archives
> > at http://archive.midrange.com/rpg400-l.
> >
> >
> --
> This is the RPG programming on the AS400 / iSeries (RPG400-L) mailing 
list
> To post a message email: RPG400-L@xxxxxxxxxxxx
> To subscribe, unsubscribe, or change list options,
> visit: http://lists.midrange.com/mailman/listinfo/rpg400-l
> or email: RPG400-L-request@xxxxxxxxxxxx
> Before posting, please take a moment to review the archives
> at http://archive.midrange.com/rpg400-l.
> 
> 
> 
> -- 
> This is the RPG programming on the AS400 / iSeries (RPG400-L) mailing 
list
> To post a message email: RPG400-L@xxxxxxxxxxxx
> To subscribe, unsubscribe, or change list options,
> visit: http://lists.midrange.com/mailman/listinfo/rpg400-l
> or email: RPG400-L-request@xxxxxxxxxxxx
> Before posting, please take a moment to review the archives
> at http://archive.midrange.com/rpg400-l.
> 

#####################################################################################
Attention:
The above message and/or attachment(s) is private and confidential and is 
intended 
only for the people for which it is addressed. If you are not named in the 
address 
fields, ignore the contents and delete all the material. Thank you.

For more information on email virus scanning, security and content
management, please contact administrator@xxxxxxxxxxxx
#####################################################################################

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

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.