Welcome. Do you know that evil spirits have access to your mind? Very often, the thoughts we have are not our thoughts. They are planted by evil spirits. (2 Corinthians 10:5)
If you have a thought that you did not choose to have, then it is not you. You should regard those thoughts as intruders and command them to leave you. You should do that until your mind becomes free. It may take some time. We are in a spiritual battle and the fight is mostly in the mind.
You also on the right track to engage your mind in good things. No one can have two thoughts at the same time. if you are thinking good things, then you cannot think the wrong thing.
I hope this helps.