The spring must be detached from the frame.
Of course, you will select a spring that is un-stretched. When looking at the spring, the spring coils must stick together and it must be impossible to insert a paper in between those spirals. Spring with outstretched coils must be replaced.
The measurement must be taken from the extremity of the hook (round tip) to the other extremity.
The most common spring sizes are in the following chart but each producer can decides on it’s own length.
When replacing your springs, a slight difference can be accepted. A 5.1″ spring can replace a 5″ or a 12,5 cm long spring can replace a 12,7 cm. But you should always try your best to respect the exact dimension.