Section 12 of this document gives a good rundown on how to do it with design script. Likely best to start at the beginning and work your way to that point though.
I recently wrote a good example script utilizing these methods for multiple string replacement, which was posted here: