I used to have this problem too, that shit is so freaking annoying!
First you need to determine why this happens to you. Is the need psychological, physiological, or both. Do you want sugar because you’re feeling down and sugar makes you happy or because your body tells you “I WANT THIS, AND I WANT IT NOW!”
In the former case, you’ll have to first figure out what triggers this and try and handle it, causes could vary from depression to just enjoying something sweet when you’re out with your friends, whatever it is, you narrow it down and figure out how to deal with it.
This could also happen if you’re feeling like your diet is too restrictive, giving it up altogether each time you give in into one small treat. In that case scenario you should maybe rethink your diet choices and find something that fits YOU personally, or perhaps giving yourself a designated cheat meal to make it both easier and healthier for your mind.
You should not beat yourself up over slip-ups, and if it’s a reappearing motive, you’ve got to readjust.
It might as well be physiological though, since this shit is biologically addictive. When you consume sugar (or any other quick carbs for that matter) your blood sugar spikes and the brain releases serotonin, making you feel happy almost immediately. Sad news is, your blood sugar drops down as fast as it goes up, and so does your mood and hunger. This is why it’s so important to understand how it works and control it.
By eating every couple of hours low glycemic index foods your sugar levels go up and drop down gradually, leaving you full and happy, with no sudden cravings or mood swings.
Honestly, the only time I do have sugar cravings now is during my period, when my hormones go ballistic, otherwise, I never have an “urge” to eat something sweet.