as important as praying is, sometimes it’s not always efficacious to just try and push or suppress the thoughts with nothing to replace them trust me, I’ve tried.
equally important, turn your mind to something else, read a good book, watch a nice movie, listen to some uplifting music, cultivate good and holy thoughts to replace the bad ones.
also, unless you know it’s a bad thought, and accept and dwell on it intentionally, then there is no sin, you may have a thought in your mind for a while without even realizing that you’re thinking it, I’ve had that happen, eventually I snap to my senses then realize what is going on in my head, that’s still not a sin.
someone on here gave a really good analogy for this once, I sincerely apologize but I forget who it was.
there’s a knock on your door, you open to find a man at your door, within a few seconds, you realize he’s up to no good so you tell him to leave and shut the door. those are the thoughts you can recognize right away.
there is aknock at your door, you open it to find a little old lady, she strikes up a conversation and you chat with her for a while, eventually, you subtely detect that she is up to no good, then you close the door. sometimes it takes a while to realize that a thought tha is creeping is bad, it’s not always so evident. still not sinful
when you enter sinful territory is when you invite both the above strangers for tea and start to plot with them about their evil deeds