Avoid allocations in string_replace_at when possible.