The copyword function

Description

The copyword function accepts up to three of the parameters described below (the last parameter is optional), and returns a value of type string which is formed by copying a word from the first parameter. NOTE: In this help topic the term word is used to mean a group of contiguous characters, seperated by another group of characters called deliminators.

Parameters

  1. The first parameter (S) is an expression of type string or type char, and contains the words to be copied.
  2. The second parameter (I) is an expression of integral type, and specifies the word to copy. Words are numbered starting from one, so it is an error if I is less than one. If I is greater than the number of words in S then no word is copied.
  3. The third parameter (D) is an expression of type string or type char, and contains the delimintors used to seperate words. If D is not present then the default deliminators (i.e. SPACE, TAB, RETURN, and LINEFEED) are used.

Example

   copyword('example', 1)                    returns  'example'
   copyword('   example    ', 1)             returns  'example'
   copyword('this is an example', 2)      returns  'is'
   copyword('example', 2)                    returns  ''

Here are some examples using "," as the deliminstor, to extract fields from comma-deliminated strings.

   copyword('1234, name, value', 1, ',')  returns  '1234'
   copyword('1234, name, value', 2, ',')  returns  ' name'
   copyword('1234, name, value', 3, ',')  returns  ' value'

Portability

Operating Systems: All
Standard Pascal: No