The spectral data of a vibrating string are encoded in its so-called characteristic function. We consider the problem of recovering the distribution of mass along the string from its characteristic function. It is well known that Stieltjes' continued fraction leads to the solution of this inverse problem in the particular case where the distribution of mass is purely discrete. We show how to adapt Stieltjes' method to solve the inverse problem for a related class of strings. An application to the excursion theory of diffusion processes is presented.