简体   繁体   English

Visual Studio 2010:基于模式的搜索替换正则表达式以外的其他?

[英]Visual Studio 2010: pattern based search replace other than regex?

I've taken over a project that is full of code like this: 我接管了一个充满代码的项目:

if (aTraceUserids[t].Trim().ToUpper() == Userid().Trim().ToUpper())
{
    // ...
}

What is - using tool-assisted expression formulation - a good way to do a search replace into something like this on a case by case base: 什么是 - 使用工具辅助表达式 - 一个很好的方法来进行搜索,在个案基础上替换为这样的东西:

if (aTraceUserids[t].Equals(Userid(), StringComparison.InvariantCultureIgnoreCase))
{
    // ...
}

Edit (thanks Dave for making me think on this further): 编辑 (感谢Dave让我进一步思考):

I know this should be possible with regular expressions , but those are hard to get right and document, so I wonder about tool assisted ways that help me both phrase the expressions and execute them. 我知道这应该可以使用正则表达式 ,但是那些很难正确和文档,所以我想知道工具辅助的方法,这有助于我说出表达式并执行它们。

Ideally I'm looking for a pattern based search/replace tool that allows me to 理想情况下,我正在寻找一种允许我使用的基于模式的搜索/替换工具

  • enter the search/replace patterns 输入搜索/替换模式
  • enter the patterns for the files and directory names to match 输入要匹配的文件和目录名称的模式
  • visually assists me with the search/replace matches, and allows me to post-edit each occurrence 在视觉上帮助我搜索/替换匹配,并允许我对每个事件进行后期编辑

I don't care much which platform as these kinds of search/replace actions will likely apply to other big code bases as well. 我并不关心哪种平台,因为这些搜索/替换操作也可能适用于其他大型代码库。

So: any solution based on *nix, Windows or web are fine. 所以:任何基于* nix,Windows或web的解决方案都可以。 CygWin and/or WINE based solutions are fine too. 基于CygWin和/或WINE的解决方案也很好。 (That's why I removed the VS2010 tag and added some platform tags). (这就是为什么我删除了VS2010标签并添加了一些平台标签)。

Since this was originally tagged with 'Visual Studio', Visual Studio itself can do regular-expression based find/replace, and the standard 'Find and Replace' dialog will let you pick and choose by hitting 'Find Next', 'Replace' or 'Replace All' as you choose. 由于这最初是用'Visual Studio'标记的,因此Visual Studio本身可以进行基于正则表达式的查找/替换,标准的“查找和替换”对话框将允许您通过点击“查找下一个”,“替换”或根据您的选择'全部替换'。

For example, I recently changed an API from; 例如,我最近更改了API;

Log.Error(string message, bool someotherArg);

to

Log.Error(string message); Log.Error(字符串消息);

And easily used Visual Studio to replace all usage throughout my codebase of this modified API like so; 并且很容易使用Visual Studio来替换这个修改过的API的代码库中的所有用法,如此;

Find what; 找什么; Log.Error({.*}, true); Log.Error({。*},true);

Replace with: Log.Error(\\1); 替换为:Log.Error(\\ 1);

The backquote in the replace line \\1 puts the grouped regex contained by {...} into that spot in the replace. 替换行\\1的反引号将{...}包含的分组正则表达式放入替换中的该点。

Handy, and built-in. 方便,内置。 Works for me. 适合我。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM