Sometimes I touch a car or a door and I feel the static electricity in my hand and it hurts sometimes. I try not to touch anything because I feel like I am going to feel this pain again. Is there a way to avoid the static electricity?
It's your clothing. You generate the static as you walk, etc. Changing the materials, or using an anti-static treatment will reduce the static. Static is worse in very dry weather.
There is no easy, obvious way to avoid building up a static charge. Carrying around an ion generator to get rid of excess charge is not exactly practical.
A static shock hurts because the discharge current passes through a very small area of skin at the point of discharge. The classic way to avoid a painful shock is to hold a key by the flat area and touch the tip of the key to the doorknob or whatever is giving you trouble. The large area of contact between your fingers and the body of the key spreads out the current flow through your skin when the key makes contact, and this low current density is not felt as pain. You'll still get a spark at the end of the key, but no shock.