简体   繁体   中英

VS2013 Find replace code and the empty line with it

I've been looking all over and can not find a way to find/replace a search term, and also remove the line with it. Here is an example of what I would like

[TestMethod]
[TestCategory("Unit")]
public void Test()
{
}

To

[TestMethod]
public void Test()
{
}

But instead (trying to replace the term with empty), I am getting this, which does make sense, but not what I desire.

[TestMethod]

public void Test()
{
}

How can I remove the line with it?

You can use regular expressions in VS . The following will match the two lines

Search: \\[TestMethod\\]\\r?\\n\\ *\\[TestCategory\\("Unit"\\)\\]

Replace: [TestMethod]

Should do what you want. Note you have to escape the brackets in your search string with \\

you need to brain visual studio 2013, select [TestCategory("Unit")] + the end of [TestMethod]<----here and copy it in FindandReplace.

在此处输入图片说明

In cases like this I generally use Sublime Text

  1. copy code from VS to sublime
  2. select the part you want to replace
  3. press ALT+F3 which will select all instances of that text
  4. press backspace all you like until you get what you want.
  5. copy and paste back yo VS.
  6. (optional) pray god for Sublime Text.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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