If your rim rubs against the brake pads in a few places, the wheel needs to be retrued. This can be done safely only if the rim is undamaged; if it was bent, for example by bottoming out on a curb, the procedure still works if the damage isn't too great but it won't last long - spokes may snap or unscrew.
I am assuming that you are using aluminum rims. If you have steel rims the procedure is the same but takes much longer because not only the spokes near the rubbing spot are involved but all other spokes too.
First, use chalk to mark the range that is rubbing. In that range, either loosen the spokes on the rubbing side or tighten the spokes on the other side. Compare the tension of the spokes in that area to the tension of spokes elsewhere to decide which of the two is right; if you can't feel a difference do both. Use a spoke wrench to adjust all spokes in the rubbing area; the ones in the center of more than the ones where the rubbing area begins and ends. Never turn the nipple more than one quarter turn at a time. If in doubt whether to tighten one side or loosening the other, go for tightening because slack spokes can unscrew all the way while riding. After adjusting, grab every crossing pair of spokes on both sides with your hand and pull them together hard (this releases tensions built when spokes are twisted). Test whether the rubbing spot got smaller, and repeat the procedure until the problem is gone.
There is usually no point in tuning the wheel better than one millimeter, that is, to less than a sideways wobble of 1mm relative to the brake pads. It often helps to move the brake pads closer together than normal to identify wobbles.
See also an article on "Replacing a Rim"