CT_BEFORATNUM

 BEFORATNUM()
 Returns the string segment before the nth occurrence of a sequence

 Syntax

     BEFORATNUM(<cSearchFor>,<cString>,[<nCounter>],
        [<nIgnore>]) --> cString

 Arguments

     <cSearchFor>  Designates the string for which the function searches.

     <cString>  Designates the string that is searched.

     <nCounter>  Designates which occurrence of the <cSearchFor> within
     the <cString> is determined.  The default value is for the last
     occurrence in the search expression.

     <nIgnore>  Designates the nuber of characters that are eliminated
     from the search.  The default value ignores none (0).

 Returns

     The function returns all the characters in <cString> in front of the
     sequence determined.  If no corresponding sequence is found, then a null
     string is returned.

 Description

     This function determines the beginning position of the nth (<nCounter>)
     occurrence of <cSearchFor> within <cString> and returns the string
     segment before this sequence.  Additionally, the function takes into
     account the CSETATMUPA() setting, which can cause differing results.

     In order to determine the nth (<nCounter>) occurrence of the
     <cSearchFor>, BEFORATNUM() searches from the left for each instance of
     this sequence.  If CSETATMUPA() is off, then the search continues after
     the last character of the sequence most recently found.  If CSETATMUPA()
     is on, the search continues after the first character of the sequence
     most recently found.

 Note

     .  Implementing SETATLIKE() allows you to use wildcard characters
        within the search sequence.

 Examples

     .  Search a string for the last appearance of a sequence:

        ? BEFORATNUM("ab", "abcabdabe")                  // "abcabd"

     .  Search a string for the first occurrence of a sequence:

        ? BEFORATNUM("ab", "abcabdabe", 1)               // ""

     .  Search a string for the first occurrence of a sequence, where
        the first three characters are not considered in the search:

        ? BEFORATNUM("ab", "abcabdabe", 1, 3)            // "abc"

     .  Search a string for the third occurrence of "xx", where the
        first four characters are not considered!  Notice the different
        results when you use the multi-pass mode:

        String := "AxxBBBBxxCCCCxxxDxxEExx"

        CSETATMUPA(.T.)
        ? BEFORATNUM("xx", String, 3, 4)            // "AxxBBBBxxCCCCx"

        CSETATMUPA(.F.)
        ? BEFORATNUM("xx", String, 3, 4)            // "AxxBBBBxxCCCCxxxD"

See Also: CSETATMUPA() SETATLIKE()

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.