Update function for string Replacement

This commit is contained in:
YuCheng Hu 2024-01-06 22:50:40 -05:00
parent 6e4ffff3e8
commit d8a7c9a945
1 changed files with 5 additions and 20 deletions

View File

@ -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))