strposmulti.pro
1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
FUNCTION STRPOSMULTI, s, subs, cpt
;+
; NAME:
; STRPOSMULTI
; PURPOSE:
; extract substring successive positions within a string, using strpos
; CATEGORY: I-4-a
; CALLING SEQUENCE:
; index=STRPOSMULTI(s, subs [, cpt] )
; INPUTS:
; s -- string : initial string
; subs -- string : substring, if '', return 0 and cpt eq 1
; OPTIONAL INPUT PARAMETERS:
; none
; KEYED INPUTS:
; none
; OUTPUTS:
; index -- long array : positions (if none -1)
; OPTIONAL OUTPUT PARAMETERS:
; cpt -- long : number of psoitions
; EXAMPLE:
; ALGORITHM:
; straightforward loop using strpos
; DEPENDENCIES:
; none
; COMMON BLOCKS:
; SIDE EFFECTS:
; none
; RESTRICTIONS:
; CALLED PROCEDURES AND FUNCTIONS:
; none
; MODIFICATION HISTORY:
; 2-Nov-1995 written with template_gen FV IAS
; 2-Oct-1997 Adapted by JPB to work outside ICE ! JPB IAS
;-
;------------------------------------------------------------
; parameters check
;------------------------------------------------------------
IF N_PARAMS() LT 2 THEN BEGIN
PRINT, 'CALLING SEQUENCE: ', $
'output=STRPOSMULTI(s, subs [, cpt] )'
STATUS(0) = ['PARAMETER MISSING', 'E']
GOTO, CLOSING
ENDIF
output=[-1l]
IF subs eq '' THEN BEGIN & output=[0l] & cpt=0 & GOTO, CLOSING & END
;------------------------------------------------------------
; function body
;------------------------------------------------------------
pos = strpos(s, subs)
WHILE pos ne -1 DO BEGIN
output = [output, pos]
pos = strpos(s, subs, pos+1)
ENDWHILE
index = where(output ne -1, cpt)
IF cpt GT 0 THEN output=output(index) ELSE output = -1
closing:
RETURN, output
END