[英]Visual Studio 2008 search and replace regex
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. 在Visual Studio中,您可以使用正则表达式进行搜索和替换。
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
搜索: rst.Fields{\\(.*\\)}\\.Value
Replace: rst\\1.ToString()
替换: rst\\1.ToString()
Thanks JaredPar! 谢谢JaredPar!
Try the following 请尝试以下方法
ASpecificCommand(\\(.*\\))\\.ASpecificProperty
搜索表达式: ASpecificCommand(\\(.*\\))\\.ASpecificProperty
ATotallyDifferentCommand\\1.ATotallyDifferentProperty
替换表达式: 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 由于存在(
涉及并因此匹配嵌套的parens,正则表达式永远不会是一个完美的解决方案。但是它应该为你发布的特定模式完成工作
The answer and solution provided helpful in doing a find-replace on messageboxes. 答案和解决方案有助于在消息框上进行查找替换。
This worked in Visual Studio 2008 (VB .NET): 这适用于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 这就是所谓的“标记表达式”,你可以在这里看到另一个例子: http : //blogs.msdn.com/b/zainnab/archive/2010/09/12/replace-in-files-tagged-expressions-vstipfind0016的.aspx
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.