The point about campaign-context bears repeating, if all you run are dungeon crawls then rangers, druids and bards are going to seem weak. Rangers and druids are even more out of their element in extra-planar campaigns. I don't think that rangers are completely out of place in a dungeon crawl, but they have to choose their animal companion accordingly and emphasize stealth over tracking.
Well, in my experience the ranger can't replace a fighter (but then again, I don't think a paladin can either, unless you are going against an inordinant amount of undead and outsiders) in all situations, but he's definitely a sound 2nd rank fighter -- I would say equal to the Monk as far as pure combat ability. So, no he's not the best, but he'll get his share of kills, and he might be the best combattant when dealing with his favored enemy.
Can the ranger replace the Rogue? Not if you have a lot of traps to overcome. A wizard can handle a few traps here and there, though. So you might not need that niche filled in your party. The ranger *can* compete with the rogue in stealth and awareness. Hide/Move Silently allow the ranger to scout with the rogue -- perhaps even better depending on the choices that the rogue has made. With his better HP, BAB and weapon selection, the ranger is more survivable than a rogue if he's discovered scouting solo. Sneak attack is great, but if your opponent survives the first round you're screwed.
Rangers used to get a bonus to the surprise roll, now they have Spot and Listen as class skills. Rogue is the only other class that has Spot as a class skill. In my opinion this is one of the most useful skills, it often is the difference between surprising or being surprised. Even in a dungeon a ranger with a maxed out spot is very beneficial.
The spells are also nice. Outdoors, there are lots of options for covering a retreat (Entangle, Windwall) as well as covering the party's progress (Nondetection, Pass without trace). The cure spells won't keep the party afloat in lieu of a cleric, but they are great for quick fixes -- much like a Paladin's lay on hands. Sure a druid can do this, but the druid is at best a mediocre combatant and definitely a lousy scout.
So how do you play a ranger in a dungeon crawl? When he isn't scouting ahead, you put him in the front rank. His spot/listen will be best put to use there and, unlike the rogue, if it lets him down he will usually be able to take the heat until the rest of the party can get organized. Very often the Ranger is the only one covering the party during the surprise round. If you have a rogue, the two can work well together as scouts. I find that the ranger pulls the rogue's fat out of the fire on a regular basis.
Cheers.