A spatial and temporal harmonic balance (STHB) method is demonstrated in this work by solving periodic solutions of a nonlinear string equation with a linear complex boundary condition, and stability analysis of the solutions is conducted by using Hill's method. In the STHB method, sine functions are used as basis functions in the space coordinate of the solutions, so that the spatial harmonic balance procedure can be implemented by a fast discrete sine transform. A trial function of a solution is formed by truncated sine functions and an additional function to satisfy the boundary conditions. In order to use sine functions as test functions, the method derives a relationship between the additional coordinate associated with the additional function and generalized coordinates associated with the sine functions. An analytical method to derive Jacobian matrix of the harmonic balanced residual is also developed, and the matrix can be used in Newton method to solve periodic solutions. The STHB procedures and analytical derivation of Jacobian matrix make solutions of the nonlinear string equation with the linear spring boundary condition efficient and easy to be implemented by computer programs. The relationship between Jacobian matrix and the system matrix of linearized ordinary differential equations (ODEs) that are associated with the governing partial differential equation is also developed, so that one can directly use Hill's method to analyze stability of the periodic solutions without deriving the linearized ODEs. The frequency-response curve of the periodic solutions is obtained and their stability is examined.