All perfect praise be to Allah, The Lord of the Worlds. I testify that there is none worthy of worship except Allah, and that Muhammad is His slave and Messenger.
It is compulsory for you to turn away your gaze from those persons who tempt you just as you are obliged not to look at women who are not Mahram to you. Allah Says (what means): {Tell the believing men to lower their gaze (from looking at forbidden things), and protect their private parts (from illegal sexual acts, etc.). That is purer for them. Verily, Allah is All-Aware of what they do.} [Quran 24:30]. So, what you mentioned about trying your best to turn away your gaze from the tempting persons is a good and commendable act. As for your friend's advice, it might be a way of remedy but the real cure is in following the Sharee'ah’s rulings. You should adhere to what is lawful in the Sharee’ah and avoid what is prohibited. You should try to marry as soon as possible if you are unmarried. If you are not able to marry at this time you should fast as much as possible. The Prophet said: "O young people! Whoever among you can marry, should marry, because it helps him lower his gaze and guard his modesty (i.e. his private parts from committing illegal sexual intercourse etc.), and whoever is not able to marry, should fast, as fasting diminishes his sexual power". [Al-Bukhari]
Allah knows best.