STRCOMPRESS Function
Compresses the white space in an input string.
Usage
result = STRCOMPRESS(string)
Input Parameters
string—The string to be compressed.
Returned Value
result—A string with all white space (blank spaces and tabs) compressed to a single space or completely removed. If string is an array, the result is an array with the same structure—each element contains a compressed copy of the corresponding element of string.
Keywords
Remove_All—If nonzero, removes all white space. Otherwise, all white space is compressed to a single space (the default).
Discussion
If not of type string, string is converted to string using the default formatting rules of PV‑WAVE. (These rules are described in the PV‑WAVE Programmer’s Guide.)
Example 1
In this example, STRCOMPRESS is used to remove the excess white space in a string.
; Create a string with excess white space characters.
s = ' This string   has     extra white space'
; Display the string with all excess white space removed.
PRINT, STRCOMPRESS(s)
; PV-WAVE prints: This string has extra white space
Example 2
This example uses STRCOMPRESS to remove all white space from each element of a three-element string array.
; Create a three-element string array.
s = strarr(3)
; Assign a string to each element of the array.
s(0) = 'a      b  c'
s(1) = '   d    e f'
s(2) = 'g     h    i'
; Remove all spaces from each element of the array and display 
; the resulting array. PM is used to display the array as 
; a column vector.
PM, STRCOMPRESS(s, /Remove_All)
; PV-WAVE prints the following:
; abc
; def
; ghi
See Also