ok, I haven't been there for a couple years but it used to be avoid the 'Tenderloin" area - with a name like that you could kind of figure it out.
There are a lot of homeless people and street hustlers around Market St/Powell St. at the bottom of the hill where the cable car turns around. And like a lot of cities the freaks seem to congregate around places where public transportation is - so bus stops, BART stations around there would be places to avoid at night.
Anything south of Market used to be bad but I heard they are cleaning that area up somewhat.
If you are in downtown SF, Union Square is a good place to get your bearings, lot of tourists, shops, hotels. So that area is pretty safe. As you go west toward Van Ness, that is where the tenderloin area is, there are more crackheads and assorted freaks. To the east from Union Square you can go toward Chinatown, which is dirty but OK to walk around. And you can load up cheap souvenirs or things like those "lucky' bamboo plants
You can ride the cable car up Powell St from the Union Sq area. Stay outside the cab so you can hang off the back like the Rice-a-roni commercial. It ends at Fisherman's Wharf. Overrated IMO. I would jump off a few blocks before the Wharf and walk toward Lombard St. (that is that 'crooked street' ) you can walk up/down Lombard. Do this during the day. Then jump on the bus from the top of that hill (or near it) or hop a cab and go down to the Golden Gate bridge and walk across that. If you are afraid of heights it will scare the shit out of you. Even if you aren't it is windy up there but the views are amazing and when you get to the other side you can get nice pictures of the San Fran skyline.
There are a ton of things to see in SF, just depends on what your interests are.