Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Case preserving find/replace in Visual Studio

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.

like image 566
user45637 Avatar asked Dec 14 '08 22:12

user45637


People also ask

How do you replace in coding?

Replace (default shortcut is Ctrl+H ). Use this item to find and replace text in the Code Editor. The search options are similar to those of the Find Text dialog. See Replace dialog for details.


2 Answers

It's not possible in Visual Studio at the moment.

You can vote for this feature:

https://developercommunity.visualstudio.com/content/idea/580810/case-preserving-search-replace.html

I usually end up opening Sublime Text, Copy & Paste the code there, perform the case-preserving replacements there and Copy & Paste back to Visual Studio.

like image 178
Tom Pažourek Avatar answered Sep 30 '22 03:09

Tom Pažourek


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

like image 22
Ray Tayek Avatar answered Sep 30 '22 04:09

Ray Tayek