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



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

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.