开发者

Visual Studio 2008 search and replace regex

I have a large solution with a lot of lines that I need to replace. In Visual St开发者_如何学JAVAudio, 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!


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


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")


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜