Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Visual Studio 2010 search for two strings within single lines of c# code

I am using Visual Studio 2010 with c#. I need to search my codebase for find all lines of code where two strings are found in the single line of code (the line of code could span multiple lines which c# allows). The two strings are not connected and I don't know what will be between them. I just want to find all occurances where it finds both strings in the line of code. Is there anyway to do this? Is there another tool outside of Visual Studio that would allow this type of search?

like image 372
user31673 Avatar asked Sep 01 '12 16:09

user31673


People also ask

How do you search for multiple words in Visual Studio?

You can search multiple line text by pasting the text into the Find input box and Replace input box. Pressing Ctrl+Enter inserts a new line in the input box.

How do I search for text in Visual Studio?

Ctrl + i - Incremental Search Most developers using Visual Studio are familiar with the “Find dialog” that you can launch by pressing the “Ctrl + F” key within the IDE.

How do I search for a word in an entire project in Visual Studio?

To use Incremental Search, just press Ctrl+I and start typing. Your search term will appear in the status bar at the bottom of the screen and your search will update as you type. Press Ctrl+I again to move to the next result and Enter or Escape to end the search.

How do I find and delete in Visual Studio?

You can use the "Find and Replace" feature of Visual Studio to delete matching lines. The key is to match the whole line including the end of line character as well. You can do this in wildcard or regular expression mode. In wildcard mode, begin the expression with * and end the expression with *\n .


1 Answers

You can use regular expressions to search for files within Visual Studio - no need for external tools for this (though, of course, you can use grep if you so wish).

See Using Regular Expressions in Visual Studio - the syntax is somewhat esoteric in that it doesn't conform to most regular expression dialects currently in use (it is different from the .NET one for sure).

Something like:

string1.+string2

Should work. If you need this in either order, try:

string1.+string2|string2.+string1
like image 81
Oded Avatar answered Oct 20 '22 00:10

Oded