Difference between revisions of "F$ELEMENT()"

From VSI OpenVMS Wiki
Jump to: navigation, search
(Added a note and example in regards to the return value when the element doesn't exist)
Line 7: Line 7:
 
'''Delimiter''' is the character used to delimit the elements in the string. For example, in "JAN/MAR/APR/MAY", the delimiter is "/", and in "John Doe", the delimiter is " ".
 
'''Delimiter''' is the character used to delimit the elements in the string. For example, in "JAN/MAR/APR/MAY", the delimiter is "/", and in "John Doe", the delimiter is " ".
 
'''String''' is the string containing the element.
 
'''String''' is the string containing the element.
 +
 +
If the select element does not exist in the string, the delimiter character is returned.
  
 
=Example=
 
=Example=
 
  <nowiki>
 
  <nowiki>
 
$ DAY_LIST = "MON/TUE/WED/THU/FRI/SAT/SUN"
 
$ DAY_LIST = "MON/TUE/WED/THU/FRI/SAT/SUN"
 +
 
$ MONDAY = F$ELEMENT(0,"/",DAY_LIST)
 
$ MONDAY = F$ELEMENT(0,"/",DAY_LIST)
 
$ SHOW SYM MONDAY
 
$ SHOW SYM MONDAY
 
   MONDAY = "MON"
 
   MONDAY = "MON"
 +
 +
$ EIGHTH_DAY = F$ELEMENT(7,"/",DAY_LIST) !non-existent element
 +
$ SHOW SYM EIGHTH_DAY
 +
  EIGHTH_DAY = "/"
 
  </nowiki>
 
  </nowiki>
  

Revision as of 16:09, 5 September 2019

F$ELEMENT() is a lexical function that extracts one element from a string of elements. It can be used, among other things, to emulate arrays in DCL.

Format

F$ELEMENT(element-number, delimiter, string)

Element numbers range from 0 to F$LENGTH(string). Delimiter is the character used to delimit the elements in the string. For example, in "JAN/MAR/APR/MAY", the delimiter is "/", and in "John Doe", the delimiter is " ". String is the string containing the element.

If the select element does not exist in the string, the delimiter character is returned.

Example

$ DAY_LIST = "MON/TUE/WED/THU/FRI/SAT/SUN"

$ MONDAY = F$ELEMENT(0,"/",DAY_LIST)
$ SHOW SYM MONDAY
   MONDAY = "MON"

$ EIGHTH_DAY = F$ELEMENT(7,"/",DAY_LIST) !non-existent element
$ SHOW SYM EIGHTH_DAY
  EIGHTH_DAY = "/"
 

See also