How do I prevent giving into cravings when trying to lose weight?

Fill up. Make sure you exercise at least 30 minutes a day, don't skip meals, avoid soda, juice, dairy, alcohol and fried foods. Eat a healthy well balanced diet! also water, organic vegetable broth, green leafy vegetables, natural pickles, apples are great to fill you up so you dont feel hungry and they are very low in calories.
Be moderate. Human nature dictates that the minute you tell yourself you can't have something, you want it even more. When trying to lose weight there is no need to tell yourself you can never have something. Eat mindfully (slowly, enjoying the food) in moderation. Sometimes you will find that healthier substitutions that are similar to your craving will hit the spot as well.