component to measure the passing of a striped string
If your string is transparent (and least to infrared) except for the markings, you can use an opto-interrupter:



It is essentially an opto-isolator with a slot in the middle into which you can insert something to block the light from the photodiode to the phototransistor.