To get back to the original topic:
There has been some very good advice here. I give this not as someone who has overcome my struggles in this area but as someone who knows what works. Sadly, I am still trying to develop the self-discipline to choose correctly, and I pray God helps me with this every day.
The key to avoid temptation is to do just that: AVOID IT!
I know it’s easier said than done, and it’s EXTREMELY EASY to focus on a little temptation, because, after all, “what could it hurt?”
We could learn this from many sources, even outside of Scripture. For example, you may have heard of the “If you give a mouse a cookie…” book. Basically, if you don’t “nip it in the bud,” the temptation will blossom into full out sin.
In other words, by compromising a little bit and just looking at inappropriate images a little (or by just looking at neutral images inappropriately), we not only make ourselves vulnerable to greater temptation, but we weaken our will to resist that temptation.
I know that, if I entertain notions about certain things, or looking at certain things, or looking
in certain ways at nearly anything, I will be tempted to sin. I certainly don’t agree with much that Luther said, but I read once that he said, “You can’t control which birds fly over your head, but you can control which ones you allow to build a nest there!”
In other words, thoughts sometimes pop into our heads, sometimes we accidentally see things we shouldn’t have. In that case, we must avert our eyes, minds, and hearts. When you find yourself thinking inappropriately about a member of the opposite sex, for example, deliberately switch your concentration to an image that brings holiness. Contemplate a crucifix, for example.
I have found that it is extremely difficult to simply stop doing a bad thing. We must do a good thing instead. Perhaps this is why the Catholic Church acknowledges the need for penance. In paying for the temporal punishment due us for our sins, we are also replacing the evil we would have done (had we continued in sin) with good (both externally, by prayer and reaching out for others, and internally, drawing us closer to the heart of God through prayer).
(I know this is long, and probably pretty rambly)
In short, avoid even the near occasion to sin. If you know you’ll end up tempted if you are online alone for more than 10 minutes, for example, time yourself. Set an alarm. When it goes off, you either choose to discipline yourself and get off the computer or you choose to weaken your self-discipline and permit the possibility of temptation.
Also, regular fasting to glorify God will help you develop self-discipline, which is good and necessary in all areas of life.
And remember, as others have said, marriage is not about sex. As a married man, I can assure you that this is a great part of the average godly marriage, but it is nowhere near the central part (just ask Mary, the greatest of all mothers and wives!). The central part is Christ. Peter Kreeft talks about marriage as a saint-making machine. Marriage is about selflessness, generosity, graciousness, and devotion, not to mention self-control (and that’s all just stuff my wife must exhibit in massive quantities not to clobber me on a daily basis!!!

)
As my youth minister once said (though I didn’t really take it to heart), marriage doesn’t “fix” the problems of sexual temptation/sexual sin.
In fact, the more temptation/sin you give into before marriage and during marriage, the more difficult the marriage will be.
As yosupman said, the sooner you take care of it, the better. Sin is always like a weedy, invasive plant. The longer you leave it there, the worse it gets, pushing its roots into the foundations of your faith and your life. Even if you don’t fertilize it (through consenting to sin further), it continues to grow. We must work to fight sin in our lives, and pray earnestly for God to cut it out of our hearts!
May God bless you in the path to holiness! Be a saint! What else is there?!