
If String is an array, then LENGTH will be a LIST, where each element of the list is an array of the lengths of the substrings for a particular element of String. Together with this result of this function, LENGTH can be used with the STRMID function to extract the matched substrings. Set this keyword to a named variable to receive the lengths of the substrings. FOLD_CASE can only be specified if the REGEX keyword is set, and cannot be used with the ESCAPE keyword. Indicates that the regular expression matching should be done in a case-insensitive fashion. Set EXTRACT to bypass this step, and cause STRSPLIT to return the substrings. These offsets, along with the lengths available from the LENGTH keyword can be used later with STRMID to extract the substrings. EXTRACTīy default, STRSPLIT returns an array of character offsets into String that indicate where the substrings are located. If EXTRACT is not specified, STRSPLIT cannot perform this editing, and the returned position and offsets will include the escape characters.įor example: print, STRSPLIT( 'a\,b,c', ',', ESCAPE= '\', /EXTRACT)ĮSCAPE cannot be specified with the FOLD_CASE or REGEX keywords. Note that if the EXTRACT keyword is set, STRSPLIT will automatically remove the escape characters from the resulting substrings. Preceding any character with an escape character prevents STRSPLIT from treating it as a separator character even if it is found in Pattern. When doing simple pattern matching, the ESCAPE keyword can be used to specify any characters that should be considered to be “escape” characters. If String is an array, then COUNT will be an array with the same number of elements. Otherwise, it will contain the number of elements in the Result array. This value will be 0 if either of the String or Pattern arguments is null. Set this keyword to a named variable that will contain the number of matched substrings returned by STRSPLIT. In this case each element in Pattern is matched up with its corresponding element in String. If Pattern is an array, then it must have the same number of elements as String. Note: If String is a string array, and Pattern is a scalar, then the same pattern is used for each string. If it is not specified, STRSPLIT defaults to splitting on spans of whitespace (space or tab characters) in String. In either case, if the EXTRACT keyword is specified, the separator characters are not included in the result. This method is slower and more complex, but can handle extremely complicated Pattern strings.

If String is an array of strings, then STRSPLIT returns a variable of type LIST, where each element of the list contains the result of calling STRSPLIT on a particular element of String. If String is a scalar string or 1-element string array, then STRSPLIT returns an array containing either the positions of the substrings or the substrings themselves (if the EXTRACT keyword is specified). Result = STRSPLIT( String ] ) Return Value Print, STRJOIN( STRSPLIT(Str, /EXTRACT), '-')

To split a string on spans of whitespace and replace them with hyphens: Str = 'STRSPLIT chops up strings.' In this case a LIST is returned with the results. STRSPLIT can also be used to split an array of strings.

The EXTRACT keyword can be used to cause STRSPLIT to return an array containing the substrings. By default, an array of the position of the substrings is returned. The STRSPLIT function splits its input String argument into separate substrings, according to the specified delimiter or regular expression. Tip: See also the IDL_String.Extract and IDL_String.Split methods, which provide similar functionality but with an object-oriented interface.
