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

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

improvements of headers (typo, links, paragraphes, etc)

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 1.6 KB
RevLine 
[2]1;+
2;
[142]3; @file_comments
[163]4; return position *array* for occurrence of a character in a string
[2]5;
[142]6; @categories
[157]7; String
[2]8;
[142]9; @param STR {in}{required}
10; the string
[2]11;
[142]12; @param SCHAR {in}{required}
13; the character to look for
[2]14;
[238]15; @returns
16; The number of matches that were found
[2]17;
[371]18; The function returns an index array similar to the
[378]19; result of the <proidl>WHERE</proidl> function
[2]20;
[142]21; @examples
[371]22;
23; find position of string "a" in the string "abcabcabc"
24;
25;   IDL> ind = strwhere('abcabcabc','a')
26;   IDL> print, ind
[238]27; [ 0, 3, 6 ]
[2]28;
[142]29; @history
[2]30;        mgs, 02 Jun 1998: VERSION 1.00
[238]31;        bmy, 30 Jun 1998: - now returns COUNT, the number
[2]32;                            of matches that are found (this is
33;                            analogous to the WHERE command)
34;
[142]35; @version
36; $Id$
37;
[2]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.
[262]45; Bugs and comments should be directed to mgs\@io.harvard.edu
[2]46; with subject "IDL routine strwhere"
[262]47;-
48FUNCTION strwhere, str, schar,count
[114]49;
50  compile_opt idl2, strictarrsubs
51;
[2]52   if (n_elements(str) eq 0) then return,-1
[238]53
[2]54   ; convert to byte
55   BStr = byte(Str)
56   BSC  = (byte(schar))[0]
[238]57
[2]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.