User's Guide

SUBSTRI

Extract a numeric substring and return the result as an integer.

Function:

Extracts a numeric substring from a larger string given a starting position and a length. The integer value of the substring is returned as a TAE integer variable.

Parameters:

STRING
Text string. This is the string the substring will be extracted from.

SPEC
Substring specification. The starting position and the length of the substring. The format of the specification is start:length, where start is the starting position of the substring (the first character of the input string is position 1) and length is the number of characters in the substring. Start+length-1 must be less than or equal to the length of STRING. The substring may not contain any nonnumeric characters.

If there is no value after the colon, then the substring will be taken from "start" to the end of STRING. If there is no value before the colon, then the substring will contain the first "length" characters of STRING. The colon must be present for the specification to be valid.

OUTVAL
Output value. The integer extracted from the original string. OUTVAL is a TAE integer variable.

Examples:

  1. LAS> substri string="123.45678" spec="5:4" outval=temp

    SUBSTRI will extract four characters from the input string starting at position five and convert them into an integer. TEMP will return the integer value of 4567.

Description/Algorithm:

Once the substring specification has been checked for validity and its starting position and length have been determined, the integer is extracted from STRING. Each character is then checked to ensure that it is a digit from 0 to 9. If so, the integer is returned in OUTVAL.

Nonfatal Error Messages:

    None.

Fatal Error Messages:

  1. [substr-invspec] Invalid input specification

    The given substring specification is invalid. Re-enter SPEC in the format start:length, where "start" and "length" are integers and start+length-1 is less than or equal to the number of characters in STRING.

  2. [substr-nonum] Substring contains non-numeric characters

    The given substring contains characters which are not part of a legal integer value. The substring must consist entirely of digits from 0 to 9.

User Notes:

  1. SUBSTRI is intended for use within a procedure PDF.

  2. OUTVAL must be a previously declared TAE integer variable.