San Francisco is a beautiful city.
Rents here are high and so are hotel prices.
This page recommends hotels that should be affordable, yet safe and in desirable areas. Most higher priced hotels are around Union Square which is not always a particularly safe area at night depending on the specific cross-street. This link leads to some unrecommended hotels in the Union Square Area. For the middle ground in affordability, I recommend Lombard Street. Lombard is a relatively busy street which is in the north part of the city, near the Golden Gate Bridge.