Visual Studio Find and Replace with Regular Expressions

One of the latest neat little features I’ve started using is Visual Studio’s Find & Replace function but using regular expressions for the search terms, for example:

Find what:
\.Item\("{(:a|_|-)*}"\)
Replace With:
!\1
Converts
.Item("cState")
Into:
!cState

If we were to break down what each regex is doing we would have the following:

In our first expression we have \.Item\("{(:a|_|-)*}"\)
  • The :a is a VS shortcut for [a-zA-Z0-9]
  • (:a|_|-) groups it with the underscore and dash giving us the effect of ([a-zA-Z0-9]|_|-)
  • * matches 0 or more of the previous expression

Now the special chars:

  • the {} tags the expression so we can use it as a variable in our replace box.
  • the replace box just has !\1, where \1 refers to the first tagged expression in our find box, if we had multiple {} in the find string, we could address them accordingly with \2, \3 and so on.
Here’s a second example using multiple tagged expressions. Another time I was refactoring a sub routine into a function.  Previously the sub was taking in a datatable by reference and modifying it locally, but now it was returning the datatable.  So every where the method was being called needed to be altered in pretty much the same way.  The following terms made the rest of my refactoring chore much easier:
Find What:
Code\.FillDataTable\({"(:a|_|-)*"}, {(:a|_|-)*}\)
Replace With:
\2 = FillDataTable(\1)
findreplace
Takes code of the format:
Code.FillDataTable("usp_FillStates", dtStates)
and changes it to:
dtStates = FillDataTable("usp_FillStates")
Thanks to the find/replace feature this saved me a bunch of time!

Visual Studio 2005 Unable to Drag Yellow Arrow – Solution Found!

Finally found a solution to a problem that was annoying me for soo long!

After getting my new PC at work and going through the various options in VS 2005 getting it setup as I wanted I found that one little feature was not working as expected.  That is the ability to change the current execution point by clicking and dragging on the yellow execution arrow while debugging.   Whenever I would try, it would only toggle a break point at the current location.
An alternate to this is the ability to right click and choose Set Next Statement which would be the same behavior but takes a fraction of time longer and requires me to consciously think about it. I was just too used to dragging the arrow around…
The related setting is Options -> Text Editor -> General -> Drag and drop text editing
With this unchecked, the arrow can’t be moved with the mouse. Checking it solves my issue, I’d finally found it!