ID:178046
 
I was just wondering, how would you replace text, such as in a language filter? Is there a simple little proc to do this or not?

(And no, I'm not making a language filter.)
These are what I use. Deadron has a text handling library floating around somewhere too.
    sd_replacetext(maintext as text, oldtext as text, newtext as text)
/* Replaces all instances of oldtext within maintext with newtext.
sd_replacetext is not case sensitive. See sd_replaceText for a
case sensitive version. */

var/F = findtext(maintext, oldtext)
while(F)
var/newmessage = copytext(maintext,1,F) + newtext + copytext(maintext,F+lentext(oldtext))
maintext = newmessage
F = findtext(maintext, oldtext)
return maintext

sd_replaceText(maintext as text, oldtext as text, newtext as text)
/* Replaces all instances of oldtext within maintext with newtext.
sd_replaceText is case sensitive. See sd_replacetext for a
non-case sensitive version. */

var/F = findText(maintext, oldtext)
while(F)
var/newmessage = copytext(maintext,1,F) + newtext + copytext(maintext,F+lentext(oldtext))
maintext = newmessage
F = findText(maintext, oldtext)
return maintext
<dm>
var/Filtered = sd_replacetext(OriginalText, "SSJ", "%&!")
will turn OriginalText "SSJWannabe" to "%&!Wannabe"