STRMID

Tip: See also the IDL_String::CharAt, IDL_String::Remove, and IDL_String::Substring methods, which provide similar functionality but with an object-oriented interface.

The STRMID function extracts one or more substrings from a string expression. Each extracted string is the result of removing characters from the input string.

Examples

Extract a substring, in this case: “is”, from a longer string and store it in another variable. Remember that the first character in the original string is at position zero (0):

myString = "IDL is fun"

subString = STRMID(myString, 4, 2)

PRINT, subString

IDL prints:

is

Extract a substring from the end of a string (quote from William Shakespeare). The string we want to remove is highlighted in yellow:

myQuote = "It is not in the stars to hold our destiny but in ourselves."

extractedStr = STRMID(myQuote, 29, 12, /REVERSE_OFFSET)

PRINT, extractedStr

IDL prints:

our destiny

Syntax

Result = STRMID(Expression, First_Character [, Length] , /REVERSE_OFFSET )

Return Value

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:

Arguments

Expression

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.

First_Character

The starting position within Expression at which the substring starts. The first character position is 0.

Length

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.

Keywords

REVERSE_OFFSET

Specifies that First_Character should be counted from the end of the string rather than the beginning. Length then proceeds from this position to the right, toward the end of the string. This allows simple extraction of strings from the end.

Version History

Original

Introduced

See Also

Comparing Strings, String Operations, String Processing, STRCMP, STREGEX, STRJOIN, STRMATCH, STRPOS, STRPUT, STRSPLIT, STRTRIM, Substrings, IDL_String