home *** CD-ROM | disk | FTP | other *** search
/ Power CD-ROM!! 7 / POWERCD7.ISO / prgmming / clipper / element.prg < prev    next >
Text File  |  1993-10-14  |  2KB  |  84 lines

  1. /*
  2.  * File......: ELEMENT.PRG
  3.  * Author....: Martin Colloby
  4.  * BBS.......: The Dark Knight Returns
  5.  * Net/Node..: 050/069
  6.  * User Name.: Martin Colloby
  7.  * Date......: 18/4/93
  8.  * Revision..: 1.0
  9.  *
  10.  * This is an original work by Martin Colloby and is placed in the public
  11.  * domain.
  12.  *
  13.  * Modification history:
  14.  * ---------------------
  15.  *
  16.  * $Log$
  17.  *
  18.  */
  19.  
  20.  
  21. /*  $DOC$
  22.  *  $FUNCNAME$
  23.  *      GT_ELEMENT()
  24.  *  $CATEGORY$
  25.  *      String
  26.  *  $ONELINER$
  27.  *      Return an element of a delimited string
  28.  *  $SYNTAX$
  29.  *      GT_Element( cString , nElement )
  30.  *  $ARGUMENTS$
  31.  *      cString  - Delimited string
  32.  *      nElement - Number of element to find
  33.  *  $RETURNS$
  34.  *      The required element of the string
  35.  *  $DESCRIPTION$
  36.  *      Finds an element in a delimited string.  The string should be
  37.  *      delimited by it's first character.
  38.  *  $EXAMPLES$
  39.  *      Return the third element of a string :
  40.  *
  41.  *          cString := GT_Element( cBigString , 3 )
  42.  *  $SEEALSO$
  43.  *
  44.  *  $INCLUDE$
  45.  *      GT_LIB.CH
  46.  *  $END$
  47.  */
  48.  
  49. *
  50. #include "GT_LIB.ch"
  51.  
  52. FUNCTION GT_Element( cString , nElement )
  53.  
  54. /****************************************************************************
  55.  Purpose - Find the nCount element of cString - delimited by "!"
  56.  Returns - The substring
  57.  Author  - Martin Colloby
  58.  Created - 29/8/90
  59. ******************************************************************************
  60.  Parameters - cString    - "!" delimited string
  61.               nElement   - Element to find
  62.  Privates   - cDelimiter - Delimiting character
  63.               nCount     - Counting variable
  64.  Externals  - None
  65. ****************************************************************************/
  66.  
  67. LOCAL cDelimiter := SUBSTR( cString , 1 , 1 )
  68. LOCAL nCount     := 0
  69.  
  70. * Ignore the first character
  71. cString := SUBSTR( cString , 2 , LEN( cString ) )
  72.  
  73. IF nElement > 1
  74.     * Remove nElement - 1 substrings from cString
  75.     FOR nCount := 1 TO nElement - 1
  76.         cString := SUBSTR( cString , AT( cDelimiter , cString ) + 1 ,;
  77.                            LEN( cString ) - AT( cDelimiter , cString ) )
  78.     NEXT nCount
  79. ENDIF
  80.  
  81. * Return the next available string
  82. RETURN( SUBSTR( cString , 1 , AT( cDelimiter , cString ) - 1 ) )
  83. *
  84.