let tr patt subst text =
let len = length text in
let text = copy text in
let rec loop pos =
if pos < len then begin
(if text.[pos] = patt then text.[pos] <- subst);
loop (pos + 1)
end
in loop 0; text