diff --git a/routines/StringReplacement.m b/routines/StringReplacement.m index 50e5cc0..7568be5 100644 --- a/routines/StringReplacement.m +++ b/routines/StringReplacement.m @@ -1,6 +1,22 @@ - N I - N TOK - N OSTR - S count=0 - F I=1:1:$L(str," ") S TOK=$P(str," ",I) S:TOK=old TOK=new S:TOK=new count=count+1 S OSTR=$G(OSTR)_" "_TOK - QUIT $E(OSTR,2,$LENGTH(OSTR)) + ;https://www.isharkfly.com/t/mumps-string-replacement/15228/1N I + READ !,"Enter String:", address + READ !,"Old String:", old + READ !,"New String:", new + DO strReplace(address,old,new,.count) + WRITE !, count + QUIT +strReplace(str,old,new,count) + SET count=0 + SET position=0 + + FOR { + SET position=$FIND(str, old, position) + QUIT:position=0 + SET count=count+1 + SET position=position + } + + WRITE !,count + SET str = $replace(str,old, new) + WRITE !, str + QUIT