Don't know what sensor to use.Any ideas?

Hello everyone. This is my first post on this community.
I have little experience with arduino. I only made a few easy projects before.
I am getting started on a new project, but i am having a hard time finding out the best possible way to achieve my goal, without using a complicated way.
This is what i am trying to do:

Imagine the mechanism inside a pull-string toy. You can pull the string and when you release it, the string is pulled back to the starting position. I want to recreate this with arduino. I want to have values for the string, meaning, i want to get a number that corresponds to the amount of string pulled out. For example, when the stirng is all inside ( the starting position) the value is 0, and as i pull, the number increases, until it reaches 1 when there is no more string left to pull. If i release the string, the value will start decreasing until all the string is pulled inside and the value is 0.

In my research i didnt find any sensor or module, dedicated to this alone. I guess i could come up with workourounds, but i would like to first get some insights and ideas from other people, possibly more experienced in this field.

Thank you for your time!
Stay healthy and safe.

The first step is for you to actually build the imaginary mechanism without any micro-controler involved. Once you get the prototype working, then consider how to modify it to add the electronic part you are imagining.

Paul

Have the string wrapped around a pulley. Count the rotation of the pulley with a rotary encoder. You know the diameter of the pulley and the angle that it has moved through. The calculation required is simple maths.

A button to zero the length when the string is fully retracted would be useful