sorry i read through your request fast and didnt catch all the details,

this should do what you want, it can be simplified quite a bit but it this way its easier to see how things work.

Code:
strange.request {
  ; replaces $2 with $3 in $1
  var %str = $1, %str2 = $strip(%str)
  var %substr = $2, %replacement = $3
  var %pos1 = $pos(%str2,%substr,1)
  var %cnt1 =  $count($left(%str2,%pos1),$left(%substr,1))
  var %pos2 = $calc(%pos1 + $len(%substr) - 1)
  var %cnt2 =  $count($left(%str2,%pos2),$right(%substr,1))
  var %real.pos1 = $pos(%str,$left(%substr,1),%cnt1)
  var %real.pos2 = $pos(%str,$right(%substr,1),%cnt2)
  return $+($left(%str,$calc(%real.pos1 - 1)),%replacement,$right(%str,$+(-,%real.pos2)))
}


$strange.request(string,substring,replacetext)

hope this is more helpful

basicly what it does it it locates the posision of the first and last chr of substr in the original string, then splices the replacment text between what exists to the left and right of thos posisions

Cobra^