The STRMID function extracts one or more substring from a string expression. Each extracted string is the result of removing characters.
Result = STRMID(Expression, First_Character [, Length] [, /REVERSE_OFFSET])
The result of the function is a string of Length characters taken from Expression, starting at character position First_Character.
The form of First_Character and Length control how they are applied to Expression. Either argument can be a scalar or an array:
If First_Character or Length is an array, the size of their first dimension determines how many substrings are extracted from each element of Expression. We call this the “stride”. If both are arrays, they must have the same stride. If First_Character or Length do not contain enough elements to process Expression, STRMID automatically loops back to the beginning as necessary. Excess values are ignored. If the stride is 1, the result will have the same structure and number of elements as Expression. If it is greater than 1, the result will have an additional dimension, with the new first dimension having the same size as the stride.
The expression from which the substrings are to be extracted. If this argument is not a string, it is converted using IDL's default formatting rules.
The starting position within Expression at which the substring starts. The first character position is 0.
The length of the substring. If there are not enough characters left in the main string to obtain Length characters, the substring is truncated. If Length is not supplied, STRMID extracts all characters from the specified start position to the end of the string.
Specifies that First_Character should be counted from the end of the string backwards. This allows simple extraction of strings from the end.
If the variable B contains the string “IDL is fun”, the substring “is” can be extracted and stored in the variable C with the command:
C = STRMID(B, 4, 2)
Original |
Introduced |