1 | ;+ |
---|
2 | ; |
---|
3 | ; @file_comments |
---|
4 | ; return position *array* for occurrence of a character in a string |
---|
5 | ; |
---|
6 | ; @categories |
---|
7 | ; String |
---|
8 | ; |
---|
9 | ; @param STR {in}{required} |
---|
10 | ; the string |
---|
11 | ; |
---|
12 | ; @param SCHAR {in}{required} |
---|
13 | ; the character to look for |
---|
14 | ; |
---|
15 | ; @returns |
---|
16 | ; The number of matches that were found |
---|
17 | ; |
---|
18 | ; The function returns an index array similar to the |
---|
19 | ; result of the where function |
---|
20 | ; |
---|
21 | ; @examples |
---|
22 | ; IDL> ind = strwhere('abcabcabc','a') |
---|
23 | ; IDL> print, ind |
---|
24 | ; [ 0, 3, 6 ] |
---|
25 | ; |
---|
26 | ; @history |
---|
27 | ; mgs, 02 Jun 1998: VERSION 1.00 |
---|
28 | ; bmy, 30 Jun 1998: - now returns COUNT, the number |
---|
29 | ; of matches that are found (this is |
---|
30 | ; analogous to the WHERE command) |
---|
31 | ; |
---|
32 | ; @version |
---|
33 | ; $Id$ |
---|
34 | ; |
---|
35 | ; Copyright (C) 1998, Martin Schultz, Harvard University |
---|
36 | ; This software is provided as is without any warranty |
---|
37 | ; whatsoever. It may be freely used, copied or distributed |
---|
38 | ; for non-commercial purposes. This copyright notice must be |
---|
39 | ; kept with any copy of this software. If this software shall |
---|
40 | ; be used commercially or sold as part of a larger package, |
---|
41 | ; please contact the author to arrange payment. |
---|
42 | ; Bugs and comments should be directed to mgs\@io.harvard.edu |
---|
43 | ; with subject "IDL routine strwhere" |
---|
44 | ;- |
---|
45 | FUNCTION strwhere, str, schar,count |
---|
46 | ; |
---|
47 | compile_opt idl2, strictarrsubs |
---|
48 | ; |
---|
49 | if (n_elements(str) eq 0) then return,-1 |
---|
50 | |
---|
51 | ; convert to byte |
---|
52 | BStr = byte(Str) |
---|
53 | BSC = (byte(schar))[0] |
---|
54 | |
---|
55 | ; Search for matches |
---|
56 | Ind = where( Bstr eq BSC, Count ) |
---|
57 | |
---|
58 | ;### bmy ### return,where(BStr eq BSC) |
---|
59 | return, Ind |
---|
60 | |
---|
61 | end |
---|