7

I have a large solution with a lot of lines that I need to replace. In Visual Studio, you can search and replace with the aid of regular expressions.

I want to replace lines like:

rst.Fields("CustomerName").Value
rst.Fields("Address").Value
rst.Fields("Invoice").Value

To:

row("CustomerName").ToString()
row("Address").ToString()
row("Invoice").ToString()

Thus keeping the dynamic text part, which can vary.

Is this possible and how?

Update, solution:
Search: rst.Fields{\(.*\)}\.Value
Replace: rst\1.ToString()

Thanks JaredPar!

Azeem
  • 11,148
  • 4
  • 27
  • 40
Michel van Engelen
  • 2,791
  • 2
  • 29
  • 45

3 Answers3

5

Try the following

  • Search Expression: ASpecificCommand(\(.*\))\.ASpecificProperty
  • Replace Expression: ATotallyDifferentCommand\1.ATotallyDifferentProperty

Note: This is not a perfect solution. Since there are (s involved and hence matching of nested parens, a regex won't ever be a perfect solution. However it should get the job done for the specific pattern you posted

JaredPar
  • 733,204
  • 149
  • 1,241
  • 1,454
  • 3
    Very very close, this did put me on the right track (using backreferences in regular expressions). The solution needs {} instead of (). Thanks! – Michel van Engelen Oct 02 '10 at 19:17
3

The answer and solution provided helpful in doing a find-replace on messageboxes.

This worked in Visual Studio 2008 (VB .NET):

Example:

MessageBox.Show("Invalid Entry","Error")

Find What:

MessageBox.Show{(.*,*)}

Replace WIth:

Error.ShowError\1\2

Results in:

Error.ShowError("Invalid Entry","Error")
John M
  • 14,338
  • 29
  • 91
  • 143
2

Looks like you have it nailed. It's what is called a "tagged expression" and you can see another example here: http://blogs.msdn.com/b/zainnab/archive/2010/09/12/replace-in-files-tagged-expressions-vstipfind0016.aspx

zainnab
  • 1,871
  • 13
  • 14