There are numerous examples online for software debounce routines for every computer language known to mankind. They all amount to simply waiting out the estimated bounce period.
For Switch Activated:
For Switch Released:
You must provide a longer delay period than any switch you use will ever bounce. Contact bounce time varies among switch types and even among switches of the same type and models. Delay time also is said to change over time with the same switch. Typical delay times used are 20 to 100 milliseconds, even when the actual bounce time may be as little as a few milliseconds.
For compute-bound applications where time is literally of the essence, such as in high-speed automated industrial machinery or robotics applications, your choice of debounce method should be Method 1: Two-Pin Debounce, or Method 2: Cross-Coupled Nand Debounce.