Ask the person who hurt your ego why they felt it necessary. You may be surprised to learn that he doesn't really have a concrete answer. At the most you may receive a mumbled, "I dunno." Often, barbed attacks have more to do with the person delivering them than they have to do with you. People tend to strike out at others when they're not feeling so confident themselves. Bringing someone else down gives them a momentary sensation of feeling powerful and in control, when the reality may be just the opposite.
Turn the tables and ask yourself why you let the remark get to you. Just as often, it's your own state of mind that perceives a comment to be hurtful. Examine your life and ask yourself if everything is going the way you planned. If it's not, then realize that you're going to be more sensitive to every perceived injustice -- from an incorrect bill at the grocery store to the light turning yellow just when you want to walk across the street. Address your hurt ego by understanding that the world is not out to get you, no matter if it appears that way.
Cultivate your personal power by understanding that you are valuable no matter what comes your way. You may not be able to stop someone from striking out, but you can change the way you deal with it. You have to acknowledge that your ego was hurt and then replace that hurt with the acknowledgment of your own self-worth. Compose a variety of positive affirmations to use in situations when your ego is hurt. Take the most resplendent quality you know you possess and affirm its power over the hurt. As Eleanor Roosevelt said, "No one can make you feel inferior without you consent." Remember that, and make it your mantra.