string-replacement function install

This commit is contained in:
YuCheng Hu 2024-01-06 22:37:22 -05:00
parent 9a1cbbe689
commit 6e4ffff3e8
1 changed files with 22 additions and 6 deletions

View File

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