Materials:

Cord switch (figure A), available in home improvement centers
Screwdriver (Philips or flat-head will depend on the type of screws in the switch)
Utility knife

figure A
The first thing you'll need to do is decide where you want to secure the switch on the length of the cord. figure B
Use the screwdriver to separate the two halves of the switch (figure C). figure C
Next, examine the plug. If both prongs of the plug are the same size, you'll be able to cut the wire on either side of the cord to install the switch. If one prong is larger than the other, however, this indicates a polarized plug. To add a switch on a cord with a polarized plug, you'll need to cut the wire on the side of the cord opposite the larger prong. (Both types of plugs are shown in figure E; the white plug is standard, the brown is polarized.) figure D
Once you've determined which side of the cord you'll need to cut - or if either side can be cut - you're ready to use your utility knife. Begin by making about a 5/8" slit in the center of the cord, between the two wires, taking care not to damage the insulation. figure E
Next, pull the wires of the cord apart to create a diamond / marquis-like shape (figure F). figure F
Then cut non-polarized wire (or either of the wires if your cord's plug is non-polarized) at the center point of the divided sections.
Make a second cut about 1/8" away from first cut to remove small center piece (figure G). figure G
Now you're ready to install the switch. Fit it into the hollow section, with one wire around each side of the center piece (figure H), 1 cut, 1 uncut. figure H
Replace top pieces of switch; hold firmly in place while repositioning the nut on the back side of the switch. Tighten screw to hold the nut in place (figure I), then test your switch! figure I