/* Rexx */ /*-------------------------------------------------------------------*/ /* */ /* REXX Exec : StrCount */ /* */ /* Description : Finds the number of occurrences of a character or */ /* string in another string. It will also return the */ /* position of the first occurrence of the string. */ /* */ /* Usage : strCount Needle HayStack Count FirstPos */ /* */ /* Count & FirstPos are optional but if omitted those names will be */ /* used as the returned PUSHed variables. */ /* */ /* */ /* Created on : 19 Jul 2018 */ /* Created by : Kevin Ferguson */ /* : Userid(MIT001) */ /* : using ABBYDALE.PROD.REXX(StrCount) */ /* */ /* Called by : XMT */ /* */ /* Calls : */ /* */ /* Change Activity : */ /* */ /* ©Copyright of Abbydale Systems LLC. */ /* */ /*-------------------------------------------------------------------*/ parse upper arg Needle Haystack Count FirstPos signal on novalue /* un-initialized vars*/ signal on halt /* attention key */ strCount: if Needle = "" then do say "strCount error: No search string passsed" signal leave end if HayStack = "" then do say "strCount error: No source string passsed" signal leave end Count = 0 FirstPos = 0 do until pos(Needle,HayStack) = 0 if pos(Needle,HayStack) > 0 then do if FirstPos = 0 then FirstPos = pos(Needle,HayStack) Count = Count + 1 w = pos(Needle,HayStack) HayStack = substr(HayStack,w+1,LENGTH(HayStack)-w) end end push Count push FirstPos leave: return /*-------------------------------------------------------------------*/ /* Trap NOVALUE Condition */ /*-------------------------------------------------------------------*/ novalue: say "NOVALUE entered from line" sigl say condition("D") say "The instruction is suppressed" address "TSO" "delstack" exit(16) /*-------------------------------------------------------------------*/ /* Trap HALT Condition */ /*-------------------------------------------------------------------*/ halt: say "HALT acknowledged in line" sigl say "Cleanup processing in progress" address "TSO" "delstack" exit(16) /*-------------------------------------------------------------------*/ /* End of StrCount */ /*-------------------------------------------------------------------*/ /*-------------------------------------------------------------------*/ /* Trap NOVALUE Condition */ /*-------------------------------------------------------------------*/ novalue: say "NOVALUE entered from line" sigl say condition("D") say "The instruction is suppressed" address "TSO" "delstack" exit(16) /*-------------------------------------------------------------------*/ /* Trap HALT Condition */ /*-------------------------------------------------------------------*/ halt: say "HALT acknowledged in line" sigl say "Cleanup processing in progress" address "TSO" "delstack" exit(16) /*-------------------------------------------------------------------*/ /* End of StrCount */ /*-------------------------------------------------------------------*/