Foreclosures are treated like every other negative item that is listed on a credit report. It will stay on there for 7 years unless you try to remove it.
You can remove it yourself by disputing to the 3 major credit bureaus. Under the Fair Credit Reporting they have to verify any negative item that you ask them to verify. This can be a process and can take several attempts or a few months depending how lucky and good you are.
You can also try to hire a Credit Restoration service to do the work for you. They are experienced and they have removed thousands of foreclosures before, just look at their stats.
If you do decide to do it yourself. Do your research first on credit repair . Because if you tip the credit bureaus off to what you are doing, they might just block you.
Good luck and hope you get it off.