$SUBSTR (get substrings)
$SUBSTR extracts a portion of a character string from a specified character string as defined by the extraction start position and the length of the character substring being extracted.
Syntax
return-value=$SUBSTR(base-character-string,extraction-start-position,length-of-extracted-string)
Values
-
return-value
Specifies the name of the variable into which the extracted substring is set.
-
base-character-string
Specifies the character string from which data is to be extracted, either as a constant or a variable. A constant must be enclosed in single quotation marks ('').
-
extraction-start-position
Specifies the position at which extraction starts, assuming the first character in the base character string is 0, either as a constant or a variable. A constant must be enclosed in single quotation marks ('').
Specify an extraction start position value of 0 or greater. If a extraction start position that does not exist is specified, a 0-byte character string is returned.
-
length-of-extracted-string
Specifies the length of a character string to be extracted (in bytes), as either a constant or a variable. If you specify a length that exceeds the end point of the base character string, only the number of characters to the end of the base character string are extracted. To unconditionally extract the entire character string from the extraction beginning position to the final character, specify a negative value.
Status
The following table lists and describes the possible statuses:
Status |
Description |
---|---|
NORMAL |
Normal end |
NODATA |
No character string existed at the specified extraction start position. |
ERROR |
— |
Script execution interrupted |
An invalid argument was specified, or an error other than the above occurred. |
Example
The following example sets the character string ABCDEFG into NAME, and then extracts ABC from NAME and sets it into VALUE:
[SET_VALUE] NAME = 'ABCDEFG' VALUE=$SUBSTR(NAME,0,3) $ECHO(VALUE)
- Execution result:
-
ABC