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



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.


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.