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



%subst(input:pos:1) means 'take the substring of the string input starting 
with the character at pos.  The substring should be a length of one 
character.'

%subst(input:pos:-1) means 'take the substring of the string input 
starting with the character at pos.  The substring should be a length of 
-1 character.'
This doesn't make sense.

I think Scott's method should work.  Basically what it is doing is reading 
each character of the string starting from the end, and storing the start 
and end positions of the string between the 2nd and 3rd last '_' 
characters (hence the pos +/-1 when storing endpos and startpos).

I'm not sure what you want the -1 to mean - if you are trying to index the 
last character of the array like you can in some other languages, RPG 
doesn't work that way.

Adam

rpg400-l-bounces@xxxxxxxxxxxx wrote on 05/04/2006 09:01:21 AM:

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

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

Follow-Ups:
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.