forked from kodamail/gscript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rgnwrd.gsf
39 lines (36 loc) · 944 Bytes
/
rgnwrd.gsf
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
function rgnwrd( str, n_start, n_end, sep )
* If separator is space, just use subwrd() for output.
* if( sep = 'sep' | sep = '' | sep = ' ' )
if( sep = 'sep' | sep = '' )
n = n_start
ret = ''
while( n <= n_end )
tmp = subwrd( str, n )
if( tmp = '' ) ; break ; endif
ret = ret % tmp % ' '
n = n + 1
endwhile
else
ret = ''
len_sep = math_strlen( sep )
len = math_strlen( str )
p = 1
i = 1
imin = -1
if( n_start = 1 ) ; imin = 1 ; endif
imax = len
while( i <= len )
c = substr( str, i, len_sep )
if( c = sep )
p = p + 1
if( p = n_start ) ; imin = i + len_sep ; endif
if( p > n_end ) ; imax = i - len_sep ; break ; endif
i = i + len_sep
else
i = i + 1
endif
endwhile
if( imin = -1 | imin > imax ) ; ret = ''
else ; ret = substr( str, imin, imax-imin+1 ) ; endif
endif
return ret