You can do it very simply with:
function! ReplaceThisWithThat(this, that)
execute "%s/" . a:this . "/" . a:that . "/g"
Which will substitute every occurrence of
a:that in the whole buffer.
If you want to perform that substitution on the content of some variable or register, you can use
substitute() in your function:
function! ReplaceThisWithThat(something, this, that)
return substitute(a:something, a:this, a:that, "g")
which doesn't make much sense.
That said, everything you need to know is in