source: trunk/SRC/ToBeReviewed/STRING/strwhere.pro @ 371

Last change on this file since 371 was 371, checked in by pinsard, 16 years ago

improvements of headers (alignments of IDL prompt in examples)

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 1.5 KB
Line 
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;
23; find position of string "a" in the string "abcabcabc"
24;
25;   IDL> ind = strwhere('abcabcabc','a')
26;   IDL> print, ind
27; [ 0, 3, 6 ]
28;
29; @history
30;        mgs, 02 Jun 1998: VERSION 1.00
31;        bmy, 30 Jun 1998: - now returns COUNT, the number
32;                            of matches that are found (this is
33;                            analogous to the WHERE command)
34;
35; @version
36; $Id$
37;
38; Copyright (C) 1998, Martin Schultz, Harvard University
39; This software is provided as is without any warranty
40; whatsoever. It may be freely used, copied or distributed
41; for non-commercial purposes. This copyright notice must be
42; kept with any copy of this software. If this software shall
43; be used commercially or sold as part of a larger package,
44; please contact the author to arrange payment.
45; Bugs and comments should be directed to mgs\@io.harvard.edu
46; with subject "IDL routine strwhere"
47;-
48FUNCTION strwhere, str, schar,count
49;
50  compile_opt idl2, strictarrsubs
51;
52   if (n_elements(str) eq 0) then return,-1
53
54   ; convert to byte
55   BStr = byte(Str)
56   BSC  = (byte(schar))[0]
57
58   ; Search for matches
59   Ind = where( Bstr eq BSC, Count )
60
61   ;### bmy ### return,where(BStr eq BSC)
62   return, Ind
63
64end
Note: See TracBrowser for help on using the repository browser.