;------------------------------------------------------------- ;+ ; NAME: ; STRFIND ; PURPOSE: ; Find and list substrings in a string array. ; CATEGORY: ; CALLING SEQUENCE: ; strfind, txt, str ; INPUTS: ; txt = Text array to search. in ; str = string to find. in ; KEYWORD PARAMETERS: ; Keywords: ; INDEX=ind Returned array of indices (-1=not found). ; /QUIET do not list lines. ; OUTPUTS: ; COMMON BLOCKS: ; NOTES: ; Notes: Ignores case. Lists lines that contain the ; text to find, also the index into the text array. ; Uses stregex so allows regular expressions. ; See help for IDL stregex for more details. ; MODIFICATION HISTORY: ; R. Sterner, 2002 Apr 22 ; R. Sterner, 2002 Apr 24 --- Added INDEX=in and /QUIET. ; ; Copyright (C) 2002, Johns Hopkins University/Applied Physics Laboratory ; This software may be used, copied, or redistributed as long as it is not ; sold and this copyright notice is reproduced on each copy made. This ; routine is provided as is without any express or implied warranties ; whatsoever. Other limitations apply as described in the file disclaimer.txt. ;- ;------------------------------------------------------------- pro strfind, txt, sub, index=w, quiet=quiet, help=hlp if (n_params(0) lt 2) or keyword_set(hlp) then begin print,' Find and list substrings in a string array.' print,' strfind, txt, str' print,' txt = Text array to search. in' print,' str = string to find. in' print,' Keywords:' print,' INDEX=ind Returned array of indices (-1=not found).' print,' /QUIET do not list lines.' print,' Notes: Ignores case. Lists lines that contain the' print,' text to find, also the index into the text array.' print,' Uses stregex so allows regular expressions.' print,' See help for IDL stregex for more details.' return endif r = stregex(txt,sub,/fold) w = where(r ge 0, c) if c eq 0 then begin print,' No matches found.' return endif if not keyword_set(quiet) then begin for i=0,c-1 do begin print,' '+strtrim(w(i),2)+': '+txt(w(i)) endfor endif end