But I say, walk by the Spirit, and you will not gratify the desires of the flesh. For the desires of the flesh are against the Spirit, and the desires of the Spirit are against the flesh, for these are opposed to each other, to keep you from doing the things you want to do. But if you are led by the Spirit, you are not under the law. Now the works of the flesh are evident: sexual immorality, impurity, sensuality, idolatry, sorcery, enmity, strife, jealousy, fits of anger, rivalries, dissensions, divisions, envy, drunkenness, orgies, and things like these. I warn you, as I warned you before, that those who do such things will not inherit the kingdom of God. But the fruit of the Spirit is love, joy, peace, patience, kindness, goodness, faithfulness, gentleness, self-control; against such things there is no law. And those who belong to Christ Jesus have crucified the flesh with its passions and desires. (Galatians 5:16-24)
Also:
But I say to you that everyone who looks at a woman with lustful intent has already committed adultery with her in his heart. (Matthew 5:28)
This is Bible. It's even New Testament. Matthew 5:28 was spoken by Jesus Himself.
Now, if you struggle with these things, it's no need to run away from God; He wants to heal them in you. He's not finished with us yet. We all have struggles and we all have things we need to give up.
That said, when a sin causes you grief (and sin NEVER comes without consequence), the Christian advice will always be first to remove the sin. You will not be able to clean up the mess until you remove the sin!
Two of Paul's fruits of the Spirits, self-control and patience, need to come into play for chastity to work. I find that these are the most lacking fruits in western culture. Patience and self-control are not compatable with what our culture tells us to do. We want things, and we want them now. We are led by feelings and emotions. If it feels good, it must be right. This is the opposite of what we're supposed to do: waiting on God to lead us and trusting Him to do what is right for us, when it's the right time.