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 |
---|
33 | |
---|
34 | if (n_params(0) lt 2) or keyword_set(hlp) then begin |
---|
35 | print,' Delete all occurrences of a character from a text string.' |
---|
36 | print,' new = delchr(old, char)' |
---|
37 | print,' old = original text string. in' |
---|
38 | print,' char = character to delete. in' |
---|
39 | print,' new = resulting string. out' |
---|
40 | return, -1 |
---|
41 | endif |
---|
42 | |
---|
43 | B = BYTE(OLD) ; convert string to a byte array. |
---|
44 | CB = BYTE(C) ; convert char to byte. |
---|
45 | w = where(b ne cb(0)) |
---|
46 | if w(0) eq -1 then return, '' ; Nothing left. |
---|
47 | return, string(b(w)) ; Return new string. |
---|
48 | END |
---|