source: trunk/STRING/strwhere.pro @ 2

Last change on this file since 2 was 2, checked in by opalod, 22 years ago

Initial revision

  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 1.8 KB
Line 
1; $Id$
2;-------------------------------------------------------------
3;+
4; NAME:
5;        STRWHERE  (function)
6;
7; PURPOSE:
8;        return position *array* for occurence of a character in
9;        a string
10;
11; CATEGORY:
12;        string tools
13;
14; CALLING SEQUENCE:
15;        pos = STRWHERE(str, schar [,Count] )
16;
17; INPUTS:
18;        STR -> the string
19;
20;        SCHAR -> the character to look for
21;
22; KEYWORD PARAMETERS:
23;        none.
24;
25; OUTPUTS:
26;        COUNT -> (optional) The number of matches that were found
27;
28;        The function returns an index array similar to the
29;        result of the where function
30;
31; SUBROUTINES:
32;
33; REQUIREMENTS:
34;
35; NOTES:
36;
37; EXAMPLE:
38;        ind = strwhere('abcabcabc','a')
39;
40;        ; returns [ 0, 3, 6 ]
41;
42; MODIFICATION HISTORY:
43;        mgs, 02 Jun 1998: VERSION 1.00
44;        bmy, 30 Jun 1998: - now returns COUNT, the number
45;                            of matches that are found (this is
46;                            analogous to the WHERE command)
47;
48;-
49; Copyright (C) 1998, Martin Schultz, Harvard University
50; This software is provided as is without any warranty
51; whatsoever. It may be freely used, copied or distributed
52; for non-commercial purposes. This copyright notice must be
53; kept with any copy of this software. If this software shall
54; be used commercially or sold as part of a larger package,
55; please contact the author to arrange payment.
56; Bugs and comments should be directed to mgs@io.harvard.edu
57; with subject "IDL routine strwhere"
58;-------------------------------------------------------------
59
60
61function strwhere,str,schar,Count
62 
63 
64   if (n_elements(str) eq 0) then return,-1
65 
66   ; convert to byte
67   BStr = byte(Str)
68   BSC  = (byte(schar))[0]
69 
70   ; Search for matches
71   Ind = where( Bstr eq BSC, Count )
72
73   ;### bmy ### return,where(BStr eq BSC)
74   return, Ind
75
76end
77   
Note: See TracBrowser for help on using the repository browser.