Thoughts are very powerful, and gain more power the more you think them so the only solution is to find out how to switch them off. As you are the source of all your thoughts, by knowing yourself as such you have power to dissolve them as soon as they arise. All you need to do is turn your attention away from your thoughts to yourself as thinker of them. Become aware of the one who is having the thought and the unwanted thought will disappear. This is true meditation and it takes practice, but if you persevere it will work without fail. To know yourself focus your attention on the innate awareness of your own existence -just being- bringing it back when thoughts which distract your attention from it arise. It's just a matter of replacing old mental habits with a new one.
