Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Global Find and Replace in Visual Studio

I have a solution with multiple projects and we need to do some serious global replacements.

Is there a way to do a wildcard replacement where some values remain in after the replace?

So, for instance if I want every HttpContext.Current.Session[“whatevervalue”] to become HttpContext.Current.Session[“whatevervalue”].ToString() the string value being passed in will be respected? I don’t want to replace “whatevervalue” I just want to append a .ToString() where the pattern matches.

Is this possible in Visual Studio?

like image 740
Ian Patrick Hughes Avatar asked Oct 13 '08 20:10

Ian Patrick Hughes


People also ask

How do I search globally in Visual Studio?

Ctrl + Shift + F – Find in Solution Sometimes you want to search across your entire solution. You can double-click each item in the “Find Results” window to navigate to that instance of the search term you searched for.

How do I use global search code in Visual Studio?

There is a global search function in Visual Studio code. You can press Ctrl + F to search this page and Ctrl + Shift + F to search globally.


1 Answers

First, Backup your Projects, just in case... Always a good idea before mass replacements.

Then, in the Find/Replace Dialog, select the Use Regular Expressions checkbox:

In the Find box, use the pattern:

HttpContext\.Current\.Session\["{.@}"\]

and in the Replace box, use:

HttpContext.Current.Session["\1"].ToString()
like image 50
Gordon Bell Avatar answered Sep 17 '22 23:09

Gordon Bell