I do one of the following, or a combination:
— mentally isolate it or put it away from me (easiest if it is at a distance from my center of consciousnes—e.g., in my foot, not in my mouth)
— treat it with awareness, acknowledging it and telling the pain-reporting functions that they are doing a good job (works for some things)
— using the breathing I used during childbirth—a technique that has been handy many times since
I have never found that swearing helps. Just the opposite, I have thought for a long time that if you give in to a lot of swearing in some adverse situation, you tend to make more of it and it can turn into a much bigger deal. My father, for instance, never swore in his life, and my husband does, heavily. I know that if they both had the same accident—stubbing a toe, just to take an example—my husband’s reaction would last a lot longer and involve more drama.