For a start, lots of people have had problems like yours. And the problems don't last for ever.
It's the same whether you are thinking about a horrible or nasty thing or whether you are worrying about something.
The first thing to do is to acknowledge your problem and say to yourself, 'Yes, I am worried about...whatever it is...however, there's nothing I can do about it right now. So I'm going to deliberately turn my mind to something else.'
Then you should think of something that you either need to get on with--like doing you homework or playing ball or something.
Or, if you're lying in bed and can't get to sleep, think of a nice story that you've read or a nice movie that you've seen and try to follow the story in your mind.
Or you might say, 'Yes, this is something I need to do (or think about) later but this isn't the time for it now.'
Or maybe you might say to yourself, 'I need to get some help with this problem. I'll worry about it until I tell someone else about it.'
If you think your problem is something that you do need some help with then once you organise things to make that happen then you will start to feel better straight away. So take some real steps to deal with it. Talk about your problem with an adult you can trust.
If none of these things work with something disgusting that you're thinking about then there is one trick that can really work well.
Don't worry about thinking these thoughts. It's normal and there's nothing to feel guilty about.
Let yourself think about it as much as you can. Even force yourself to think about it when you don't want to. After a while your brain will get so tired of it that it will forget all about it. (That sounds weird, but it works!)
All the best in sorting out your problem.
Remember--the main thing is to tell yourself it's no big deal. Eventually the thoughts will go away.