;------------------------------------------------------------------------------ ; NAME: CLEAN ; ; PURPOSE: To remove all unprintable characters from the given string ; ; CALLING SEQUENCE: Result = CLEAN (text, [/SPACE]) ; ; INPUTS: ; Text: String of characters to be cleaned ; OUTPUTS: ; Result: String of characters removed of all unprintable characters ; ; OPTIONAL INPUTS: ; SPACE: removes all unprintable characters including all space chars. ; ; EXAMPLE: ; To remove all unprintable chars except space ; IDL> word = CLEAN ('the [tab]file is [lf][cr]') ; IDL> print, word ; the file is ; To remove all unprintable chars including space ; IDL> word = CLEAN ('the [tab]file is [lf][cr]') ; IDL> print, word ; thefileis ; ; PROCEDURES USED: none ; ; MODIFICATION HISTORY: ; Written by Puneet Khetarpal, January 15, 2003 ; February 14, 2003: modified code to include option of removing space ; characters also and modified final processing of ; text for robustness ; ;------------------------------------------------------------------------------ function CLEAN, text, SPACE=space if keyword_set(SPACE) then space = 1 else space = 0 length = strlen(text) clength = length - 1 if length NE 0 then begin btext = byte(text) nbtext = bytarr(length) count = 0 if SPACE EQ 0 then begin for c = 0, clength do begin if NOT(btext[c] LT 32B) then begin nbtext[count] = btext[c] count = count + 1 endif endfor endif else begin for c = 0, clength do begin if NOT(btext[c] LE 32B) then begin nbtext[count] = btext[c] count = count + 1 endif endfor endelse if count NE 0 then text = string(nbtext[0:count-1]) else text = '' endif return, text end