From d8a7c9a945a57cd83748fff96239868bc1685da5 Mon Sep 17 00:00:00 2001 From: YuCheng Hu Date: Sat, 6 Jan 2024 22:50:40 -0500 Subject: [PATCH] Update function for string Replacement --- routines/StringReplacement.m | 25 +++++-------------------- 1 file changed, 5 insertions(+), 20 deletions(-) diff --git a/routines/StringReplacement.m b/routines/StringReplacement.m index 7568be5..041d4be 100644 --- a/routines/StringReplacement.m +++ b/routines/StringReplacement.m @@ -1,22 +1,7 @@ ;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) + N I + N TOK + N OSTR 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 + 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))