Monday, January 3, 2011

Regular Expression Replacement in Visual Studio

Text replacement in visual studio using Regular Expression can be very handy during refactoring in large projects.

E.g. to find "new DoubleFieldEntry(Convert.ToString(_obj.[Text to Keep]));" and replace with "new DoubleFieldEntry(_obj.[Text to Keep]);"

The find regular expression is "new DoubleFieldEntry\(Convert.ToString\({_obj.*}\)\);" and the replace regular expression "new DoubleFieldEntry\(\1\);"

The above replacement in the figure replaces codes in the current project such as "new IntFieldEntry(Convert.ToString(_obj.SaleID))" to "new IntFieldEntry(_obj.SaleID)"

No comments:

Post a Comment