/* Rexx */ /*-------------------------------------------------------------------*/ /* */ /* REXX Exec : STRREPL */ /* */ /* Description : Replace one string with another in given string. */ /* */ /* Usage : new = strRepl(Input,Find,Replace,Limit) */ /* */ /* Limit, if omitted, will default to 999999 and this should catch */ /* all the occurences of the find string and replace them. */ /* */ /* */ /* Created on : 19 Jul 2018 */ /* Created by : KEVIN FERGUSON */ /* : Userid(MIT001) */ /* : using ABBYDALE.DEVL.REXX(STRREPL) */ /* */ /* Called by : */ /* */ /* Calls : */ /* */ /* Change Activity : */ /* */ /* ©Copyright of Abbydale Systems LLC. */ /* */ /*-------------------------------------------------------------------*/ signal on novalue /* un-initialized vars*/ signal on halt /* attention key */ strRepl: Orig = ARG(1) Oldtxt = ARG(2) Newtxt = ARG(3) Limit = ARG(4) Newstr = '' StrCount = 0 If DATATYPE(limit) <> 'NUM' then do Limit = 999999 end work = Orig Do while POS(Oldtxt,work)<> 0 Newstr = Newstr||substr(Work,1,POS(Oldtxt,work)-1)||Newtxt work = substr(work,POS(Oldtxt,work)+LENGTH(oldtxt)) StrCount = StrCount + 1 if StrCount >= limit then leave end Newstr = Newstr||substr(work,1) return newstr /*-------------------------------------------------------------------*/ /* 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 STRREPL */ /*-------------------------------------------------------------------*/ /*-------------------------------------------------------------------*/ /* 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 STRREPL */ /*-------------------------------------------------------------------*/