A constrained string method and its numerical analysis