If you feel comfortable working with electricity you can find the information for rewiring most kinds of electric garden tools. However be safe and if you don't feel up to the task have it repaired by a professional or simply buy a new one.
If your weed whacker is electric look at the connections to the battery of your weed whacker, there probably is a loose connection or the leads don't connect.
Can vary depeinding on brand, but generally just open the housing and you'lll see the old cord has 2 or 3 wires (black and white and sometimes green). Just run a cord maintaining the same color code and positioning.