Replacing a piano string is not as simple as it first seems. New piano strings are very unstable and need time to stretch before they will hold a pitch for an extended period of time. Often times, a new string will require upwards of five or six tunings before it is acceptably stable.
Because of this, it is often a better idea to splice a broken string rather than replace it completely. This is especially true for wound bass strings which are both more expensive and have greater tonal variation than plain gauge strings.
Strings will almost always break near the tuning pin or the hitch pin. I have never seen a string break in the middle. This is helpful because it means that we can remove the short piece of the broken string and tie in a piece of new piano wire. This new length of wire will stretch just like a full new string would, but since the stretch will be limited to a short section it might only take one or two tunings to stabilize.
To splice a wire, we will use the piano tuner's knot. This knot is very simple, however it can be a bit difficult to actually tie due to the stiffness of piano wire.
To begin, make a clockwise loop in the lower wire. Be sure that the working end of the wire passes underneath the standing part of the wire.
Next, make a counter-clockwise loop in the upper wire. Again, be sure that the working end passes underneath the standing end.
In the lower wire, fold the loop 90 degrees downward, so that the tip of the wire is inside of the bend.
Hold the upper wire across the lower wire with the end pointing upwards.
Pull the upper wire across to interlock the upper wire loop with the standing part of the lower wire.
Rotate the upper wire so that tips of the two wires are pointing in opposite directions.
Bend the upper wire in order to feed the standing end through the loop of the lower wire.
That is the piano tuner's knot! When this knot it pulled tight during tuning, the two loops will lock against each other and hold tension.
When tying this knot in a piano, you want the knot to end up in a location where it wont be touching anything (i.e. the plate, tuning pins, other strings). Sometimes it might take a few tries to get the knot to be in an acceptable location.