!**********************************************************************
!* Find Pattern in String *
!**********************************************************************
!* *
!* INPUT: $I_dir - Direction B=Bwd F=Fwd [Default] *
!* $I_string - Input String *
!* $I_find - Search String *
!* #I_pos - Start Position *
!* OUTPUT: #O_pos - Position in String (or ZERO) *
!* *
!* To de-activate this function: *
!* #define INSTR_Func_Remove *
!* *
!**********************************************************************
!* *
!* EXAMPLE: do INSTR-Func('B', 'HELLO, WORLD', 'L', 12, #O_pos1) *
!* do INSTR-Func('B', 'HELLO, WORLD', 'L', 10, #O_pos2) *
!* do INSTR-Func('F', 'HELLO, WORLD', 'W', 1, #O_pos3) *
!* *
!* RESULTS: #O_pos1 = 11 ('L' found (backwards) from pos.12). *
!* #O_pos2 = 4 ('L' found (backwards) from pos.10). *
!* #O_pos3 = 8 ('W' found (forwards) from pos. 1). *
!* *
!**********************************************************************
#ifndef INSTR_Func_Remove
begin-procedure INSTR-Func($I_dir, $I_string, $I_find, #I_pos, :#O_pos)
let #O_pos = 0
let #len = length($I_string)
let #adj = length($I_find)
let #pos = #I_pos
let #dir = 1
if $I_dir = 'B'
let #dir = -1
end-if
while #pos > 0
and #pos <= #len
let $chars = substr($I_string, #pos, #adj)
if $chars = $I_find
let #O_pos = #pos
break
end-if
let #pos = #pos + #dir
end-while
end-procedure
#endif
!**********************************************************************
|