Update function for string Replacement
This commit is contained in:
parent
6e4ffff3e8
commit
d8a7c9a945
|
@ -1,22 +1,7 @@
|
||||||
;https://www.isharkfly.com/t/mumps-string-replacement/15228/1N I
|
;https://www.isharkfly.com/t/mumps-string-replacement/15228/1N I
|
||||||
READ !,"Enter String:", address
|
N I
|
||||||
READ !,"Old String:", old
|
N TOK
|
||||||
READ !,"New String:", new
|
N OSTR
|
||||||
DO strReplace(address,old,new,.count)
|
|
||||||
WRITE !, count
|
|
||||||
QUIT
|
|
||||||
strReplace(str,old,new,count)
|
|
||||||
SET count=0
|
SET count=0
|
||||||
SET position=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))
|
||||||
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
|
|
||||||
|
|
Loading…
Reference in New Issue