You can tell your mind, "I shall not allow you to go in your own way. Now I want to think of God." Repeat the name of God inwardly or aloud. Then say, "I want to have purity in my whole existence." Then repeat "purity, purity, purity." At that time you are not allowing your mind to think of impurity or of any other thing. Don't give your mind a chance to wander; simply utilise your mind for your own purpose. You have millions of things to accomplish in and through the mind. But the mind is so naughty and mischievous that if you don't utilise it, it will utilise you.