STRMID Function
Extracts a substring from a string expression.
Usage
result = STRMID(expr, first_character, length)
Input Parameters
expr—The expression from which the substring is to be extracted.
If not of type string, expr is converted to string using the default formatting rules of PV‑WAVE. (These rules are described in the section Free Format Output in Chapter 8 of the PV‑WAVE Programmer’s Guide.)
first_character—The starting position within expr at which the substring starts. The first character position is position 0.
length—The length of the substring. If there are not enough characters left in the main string to obtain length characters, the substring will be truncated.
Returned Value
result—A string of length characters taken from expr, starting at character position first_character. If expr is an array, the result is an array with the same structure, with each element containing the substring of the corresponding expr element.
Keywords
None.
Example
In this example, STRPOS is used to locate the first occurrence of the string a within a larger string. Function STRMID is then used to extract a substring from that position. Function STRPOS is used to locate the second occurrence of the string a, and finally, STRMID is used to extract another substring from this second position within the larger string.
; Create a string in the variable a.
a = 'Extract a substring from a string'
 
; Locate first occurrence of the string 'a '.
POS = STRPOS(a, 'a ')
; Extract 11 characters from a, starting at POS.
PRINT, STRMID(a, pos, 11)
; PV-WAVE prints: a substring
; Search for the second occurrence of the string 'a ' by searching
; from the character position that is one greater than the first 
; occurrence of that string. Extract 8 characters from a, 
; starting at the new POS.
POS = STRPOS(a, 'a ', pos + 1)
PRINT, STRMID(a, pos, 8)
; PV-WAVE prints: a string
See Also