How to delete pre existing code from arduino?

You don't need to, when you upload new code the old code is gone.