replacetext(), deletetext(), inserttext()
|
|
One-liner snippets from my tiny texthandling library.
proc replacetext(t,t2,t3)return copytext(t,1,findtext(t,t2))+t3+copytext(t,findtext(t,t2)+length(t2),0) deletetext(t,t2) return copytext(t,1,findtext(t,t2))+copytext(t,findtext(t,t2)+length(t2),0) inserttext(t,t2,n) return copytext(t,1,n>0?n+1 : length(t)+1)+t2+copytext(t,n>0?n+1 : length(t)+1,0)
mob/verb HelloMars()src<<replacetext("Hello world!","world","Mars") //Replaces "world" with "Mars" HelloWorld()src<<deletetext("Hello stuff in the world!","stuff in the ") //Outputs "Hello world" HelloBLAHWorld()src<<inserttext("HelloWorld","BLAH",5) //Inserts "BLAH" after "Hello", which is 5 characters long.
|
Not only do these procs leave much to be desired in the way of iterations (replacetext() and deletetext() would only replace/delete the first instance of t2), they don't work very well, and don't offer much in the way of differentiating between case-sensitivity (you only allow for case-insensitive operations).
The following breaks your first two procs:
A more proper replacetext() function would look like this: