views:

160

answers:

2

There seems to be no built-in support for case preserving find/replace in VisualStudio (see also a respective feature request).

What I mean is: searching for 'BadJob' and replacing with 'GoodJob' would do the following replacements

'badjob' -> 'goodjob'  
'BadJob' -> 'GoodJob'  
'badJob' -> 'goodJob'  
'BADJOB' -> 'GOODJOB'

So I am looking for a macro/add-in which implements case preserving find/replace. And if none exists, what is a good starting point to write my own (preferably based on the built-in find/replace capabilities).

Update:
I know I can make 4 manual replacements doing the job, but I am looking for a way to do it automatically in VS (like e.g. Emacs does it). A common scenario: a variable named 'foo' and some functions DoFoo(), GetFoo(), ... and some additional comments containing 'foo' 'Foo' etc. Now rename 'foo' to bar' yielding variable 'bar', functions DoBar(), GetBar() etc. by ONE find/replace.

+3  A: 

open up the find options when you do the find/replace. check the case-sensitive option. you will have to do the flavours manually unless you do something like: http://www.aaronlerch.com/blog/2007/03/28/visual-studio-find-and-replace-regular-expressions/, or use something like: http://www.download3k.com/MP3-Audio-Video/Utilities-Plug-Ins/Download-Find-Replace.html

Ray Tayek
Doing 4 manual case-sensitive replacements is exactly what I NOT want to do. I am looking for a 'smart' find/replace in VS which does it this automatically (Emacs e.g. does that).
A: 

I know this doesn't answer your question exactly as you asked it, but for renaming variables and method names you can avoid the whole problem by right clicking on the identifier and using the rename option on the shortcut menu. That will update any references to that variable or method name.

Caveats:
It only works in the scope of the current solution.
It only updates references in managed code.
It won't update literal strings such as "badcode"
It won't update your comments.

This is one of my favorite features in VS2005/2008.

JohnFx
This only applies if you are using a .NET language and is not actually a feature if you are using C++.
jheriko