I would like to search / replace text but only text in quotes in Visual Studio 2010 IDE, is this possible ?
For example I want to change
oldValue
in
newValue
but only if searched text is surrounded with quotes or double quotes, something like this
string something = "This string have oldValue"; // replace this
int oldValue = 44; // don't replace this
btw. this is not limited on C# or VB.NET code, I would like to do this on other file types like for example SQL scripts etc.
You can use the regular expressions option in Visual Studio’s find dialog.
Your “find what” would look like:
{".*}oldValue{.*"}This will find a double quote, followed by any characters, then your “oldValue”, then followed by any characters and finally another quote.
Your “replace with” would then be:
\1newValue\2This will leave whatever was in front of or after the oldValue intact.
Since this regex isn’t looking for values inside quotes, only values preceded and followed by quotes it will incorrectly work on the following:
"abc" oldvalue "123"