For max performance, I would leave the code in the triggers. You will incur a LOT of overhead moving this to a function.
Btw, you should also stack/imbed them for best performance, something like:
SET @MyVariable = Replace(Replace(Replace(Replace (@MyVariable, '"', '\x022'), '''', '\x027'), char(10), '\x0a'), char(13), '\x0d')