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