I started writing a program that's supposed to replace every instance of input2 inside the string input1 with input3.
The code I have works ok, but it's prone to infinite loops when input2 is part of input3.
If anyone is familiar with string manipulation, please help me work this out.
This is the code:
*strbound() returns the lower and upper bounds of a string and its length in the form {lower,upper,length}
*Its inputs are similar to inString's
rplcstr(in,ss,rs)
:Func
:Local t,n
:1→n
:While inString(in,ss,n)≠0
:strbound(in,ss,n)→t
:t[2]→n
:If n=0 or t[1]+t[2]=0
:Return in
:mid(in,1,t[1]-1)&rs&mid(in,t[2]+1,dim(in))→in
:EndWhile
:Return in
:EndFunc