D.T.
E.,
This is simple. He is getting attention for swearing. Stop giving it to him. Ignore it completely. You may be embarrassed a few times about what comes out of his mouth in public, but modeling good behavior is the best cure for this one. The doctor is right. Eventually the bad words will disappear from his vocabulary.
What we do with our kids who are 7, 10, and 12, is acknowledge that there are socially unacceptable words out there. We know what they are, and for the most part, the kids know what they are. We acknowledge that they have heard them out in the world, but we make it very clear that we choose to not make them part of our polite vocabulary. When I "slip", I apologize to the kids.
Our kids have never used words that I object to in my presence, and I have never had a complaint about one of them using objectionable language in the presence of another adult. The language they use amongst their peers is less in my control, but so far, I haven't had any parent complain that their child learned any colorful language from mine.
Sometimes they'll ask me what a certain word or hand gesture means and I will simply tell them that it's offensive, and they're sure to learn its meaning soon enough, but it won't be from me.
Best of luck,
D. T