It’s all about discipline. You need to decide what you want, the short term or long term satisfaction. That drive has to come from you.
Some tips to help you get there: try to picture food as what it can do for you, what nutrients it can provide you, and how you will feel afterwards. If you associate chocolate with 45g of saturated fat per 100g, and with how you feel afterwards, then you might feel stronger in turning it down.
You can also fill up on what you have for dinner to avoid late night snacking. Fruit and vegetables take up more space per calorie than meat or carbs.
This brings me to other things you can have instead of chocolate/ice cream/doughnuts/soda if you simply must have something. Fresh fruit like a banana or some strawberries. Dried fruit like apricots and dates. Small amounts of nuts like pistachios and cashews. Skinny popcorn is great too.
Try switching to these healthy treats first and then gradually weening yourself completely off eating when you’re not hungry. If you know you’re just craving food because you’re bored then try herbal tea instead, there are so many flavours to choose from, it fills you up with liquid, and it gives you something to do with your hands while you’re watching TV or whatever.
If you find yourself hungry when you’re in bed trying to go to sleep, try keeping a bottle of water in arms reach and drinking that throughout the night. If you’re really starving right before bed it’s OK to have a little something (trying to sleep hungry is the worst) - I usually half half a banana with some peanut butter.
Hope this helps!