When someone shares a problem with you, it's often appropriate to share similar experiences from your own life.
For instance, if they are worried about failing a class, you might share with them a time when you almost failed a class – either to empathize with them, or to encourage them that you survived and they will too.
However, there is a fine line between sharing an experience to help another person, and sharing an experience to put the spotlight on yourself.
It's okay to tell a suffering friend that you know how painful breakups can be. It's not okay to spend ten minutes complaining about your ex, or tell them, “I had that problem too and then I solved it” and talk about how great your life is now.
Be particularly careful to avoid the “bigger fish” respose. The term comes from a habit among fisherman who will interrupt anyone telling a story about catching a big fish in order to tell about the time they caught an even bigger fish.
Among fishing buddies, this is a bit irritating but not a big deal. But if your friend comes to you for support, it's hurtful to respond, “That's nothing! I'm the one who really has it rough – let me tell you about my problems...” Not only did you fail to give your friend support, but you also hurt their feelings by acting like their problem didn't matter.
You also want to avoid reacting like their problem is the biggest thing in the world (otherwise known as the "your fish is gigantic and incredibly scary" response.) Their problem might be serious, but life goes on. Don't act like their problem is the worst thing in the world, or you have no idea how to handle it. That will just make them feel worse about the problem. No matter how you're feeling about their problem, keep your focus on them.
Bottom line: don't make it about you. Use stories from your own experience sparingly, and make sure to only tell stories to encourage the other person – then put the spotlight right back on them. And no matter how you feel about their problem, don't let your emotions take center stage -- again, keep the spotlight on them.