[2] | 1 | ;------------------------------------------------------------- |
---|
| 2 | ;+ |
---|
| 3 | ; NAME: |
---|
| 4 | ; DELCHR |
---|
| 5 | ; PURPOSE: |
---|
| 6 | ; Delete all occurrences of a character from a text string. |
---|
| 7 | ; CATEGORY: |
---|
| 8 | ; CALLING SEQUENCE: |
---|
| 9 | ; new = delchr(old, char) |
---|
| 10 | ; INPUTS: |
---|
| 11 | ; old = original text string. in |
---|
| 12 | ; char = character to delete. in |
---|
| 13 | ; KEYWORD PARAMETERS: |
---|
| 14 | ; OUTPUTS: |
---|
| 15 | ; new = resulting string. out |
---|
| 16 | ; COMMON BLOCKS: |
---|
| 17 | ; NOTES: |
---|
| 18 | ; MODIFICATION HISTORY: |
---|
| 19 | ; R. Sterner. 5 Jul, 1988. |
---|
| 20 | ; Johns Hopkins Applied Physics Lab. |
---|
| 21 | ; RES 11 Sep, 1989 --- converted to SUN. |
---|
| 22 | ; R. Sterner, 27 Jan, 1993 --- dropped reference to array. |
---|
| 23 | ; |
---|
| 24 | ; Copyright (C) 1988, Johns Hopkins University/Applied Physics Laboratory |
---|
| 25 | ; This software may be used, copied, or redistributed as long as it is not |
---|
| 26 | ; sold and this copyright notice is reproduced on each copy made. This |
---|
| 27 | ; routine is provided as is without any express or implied warranties |
---|
| 28 | ; whatsoever. Other limitations apply as described in the file disclaimer.txt. |
---|
| 29 | ;- |
---|
| 30 | ;------------------------------------------------------------- |
---|
| 31 | |
---|
| 32 | FUNCTION DELCHR, OLD, C, help=hlp |
---|
[115] | 33 | ; |
---|
| 34 | compile_opt idl2, strictarrsubs |
---|
| 35 | ; |
---|
[2] | 36 | |
---|
| 37 | if (n_params(0) lt 2) or keyword_set(hlp) then begin |
---|
| 38 | print,' Delete all occurrences of a character from a text string.' |
---|
| 39 | print,' new = delchr(old, char)' |
---|
| 40 | print,' old = original text string. in' |
---|
| 41 | print,' char = character to delete. in' |
---|
| 42 | print,' new = resulting string. out' |
---|
| 43 | return, -1 |
---|
| 44 | endif |
---|
| 45 | |
---|
| 46 | B = BYTE(OLD) ; convert string to a byte array. |
---|
| 47 | CB = BYTE(C) ; convert char to byte. |
---|
[115] | 48 | w = where(b ne cb[0]) |
---|
| 49 | if w[0] eq -1 then return, '' ; Nothing left. |
---|
| 50 | return, string(b[w]) ; Return new string. |
---|
[2] | 51 | END |
---|