let replace_string ~src ~find ~replace_with =
let l_src = String.length src in
let l_find = String.length find in
let res_buf = Buffer.create (2 * l_src) in
let i = ref 0 in
while !i < l_src do
if (!i <= l_src - l_find) && (String.sub src !i l_find = find) then (
Buffer.add_string res_buf replace_with;
i := !i + l_find;
) else (
Buffer.add_char res_buf src.[!i];
incr i;
)
done;
(* Buffer.add_substring res_buf src (l_src - l_find + 1) (l_find - 1); *)
Buffer.contents res_buf