Index Page posr_c

A B C D E F G H I J K L M N O P Q R S T U V W X

Procedure Abstract Required_Reading Keywords Brief_I/O Detailed_Input | Detailed_Output Parameters Exceptions Files Particulars Examples | Restrictions Literature_References Author_and_Institution Version Index_Entries

#### Procedure

       SpiceInt posr_c ( ConstSpiceChar    * str,
                         ConstSpiceChar    * substr,
                         SpiceInt            start  )

#### Abstract

       Find the first occurrence in a string of a substring, starting at
       a specified location, searching backward.

#### Required_Reading

       SCANNING

#### Keywords

       CHARACTER
       SEARCH
       UTILITY

#### Brief_I/O

       VARIABLE  I/O  DESCRIPTION
       --------  ---  --------------------------------------------------
       str        I   Any character string.
       substr     I   Substring to locate in the character string.
       start      I   Position to begin looking for substr in str.

       The function returns the index of the last occurrence of substr in
       str at or preceding index start.

#### Detailed_Input

       str        is any character string.

       substr     is a substring to look for in str.  Spaces in substr are
                  significant, including trailing blanks.

       start      is the position in str to begin looking for substr. start
                  may range from 0 to n-1, where n is the number of
                  characters in str.

#### Detailed_Output

       The function returns the index of the beginning of the last
       substring of str that begins at or before index start and is equal
       to substr. If the substring cannot be found after start, the
       function is returns -1.

#### Parameters

       None.

#### Exceptions

       1) The error SPICE(NULLPOINTER) is signaled if either of
          the input string pointers is null.

       2) If start is less than 0, the search begins at the first
          character of the string.

       3) If start is greater than or equal to the length of the string,
          posr_c returns -1.

       4) The function returns -1 if either of the input strings is empty.

#### Files

       None.

#### Particulars

       posr_c is case sensitive.

       An entire family of related CSPICE routines

          cpos_c
          cposr_c
          ncpos_c
          ncposr_c
          pos_c
          posr_c

       is described in the Required Reading.

#### Examples

       Let string == "AN ANT AND AN ELEPHANT        "
                      012345678901234567890123456789

       Normal (Sequential) Searching:
       ------------------------------

          posr_c ( STRING, "AN",  29 ) == 19
          posr_c ( STRING, "AN",  18 ) == 11
          posr_c ( STRING, "AN",  10 ) ==  7
          posr_c ( STRING, "AN",   6 ) ==  3
          posr_c ( STRING, "AN",   2 ) ==  0

       start out of bounds:
       --------------------

          posr_c ( STRING, "AN", -6 ) == -1
          posr_c ( STRING, "AN", -1 ) == -1
          posr_c ( STRING, "AN", 30 ) == 19
          posr_c ( STRING, "AN", 43 ) == 19

       Significance of Spaces:
       -----------------------

          posr_c ( STRING, "AN",    29 ) ==  19
          posr_c ( STRING, " AN",   29 ) ==  10
          posr_c ( STRING, " AN ",  29 ) ==  10
          posr_c ( STRING, " AN ",   9 ) ==  -1
          posr_c ( STRING, " AN  ", 29 ) ==  -1

#### Restrictions

       None.

#### Literature_References

       None.

#### Author_and_Institution

       N.J. Bachman    (JPL)
       W.L. Taber      (JPL)

#### Version

       -CSPICE Version 1.0.0, 15-AUG-2002 (NJB) (WLT)

#### Index_Entries

       position of substring reverse search

#### Link to routine posr_c source file posr_c.c

    Wed Apr  5 17:54:40 2017