It depends on the place as well.
Italy and Flanders, for example, were war zones very frequently so it made sense to keep updating fortifications, updating from high walls to trace italienne and some of these were still in use as late as WW1. There is film of Vienna's defensive walls being taken down in the 1880s(?) to be converted into the Ringstrasse.
Here in York, on the other hand, history was reasonably tranquil and the high stone walls - used mostly for funnelling people into the city through the few gateways and thus extracting tolls from traders - remained in place until the English Civil War, where they withstood a siege in 1644.
As Brickie78 said, it depends on the place. In the Netherlands most of the city walls were torn down over the course of the 19th century. Improvements in the range and firepower of artillery had reduced their effectiveness, and they restricted the growth of cities.
Bear in mind that by this time we're talking about the fairly low, angled walls of the trace Italienne, with a core of compacted earth. Not the tall, thin, stone walls of a medieval city.
In the case of Amsterdam the walls were eventually replaced by the Stelling van Amsterdam a ring of forts around the city (at a distance of 15-20 km from the city centre). Combined with planned inundations (a traditional Dutch defensive measure) this ring was to protect the capital in case of invasion, if all other defenses failed. As it happened, when WWI broke out, the Germans respected Dutch neutrality. how much this decision was influenced by the fortifications is up for debate.
By the time the Netherlands were invaded, in 1940, new technology had made the ring around Amsterdam obsolete, so it never saw active duty.
EDIT: the ring is currently a UNESCO world heritage site, some of the forts are open to the public, as musea, art galleries and restaurants.