开发者

Visual Studio 2008: Find and Replace with new line character?

开发者 https://www.devze.com 2022-12-24 01:08 出处:网络
Sometimes i would like to search for text containing a new line character 开发者_开发问答and there are other times i would like to replace text with a new line character.

Sometimes i would like to search for text containing a new line character 开发者_开发问答and there are other times i would like to replace text with a new line character.

How can i do this with visual studio 2008?


Use a RegEx search:

In the Find Dialog - Expand "Find Options" Check the box for Use: Regular Expressions

Next to the search box there is now an arrow that is active, it will show you available RegEx options/values.

The value you want will be \n. So "SearchValue\n" should do it.

Be aware that that its not a standard RegEx that you use, it's VS specific. Replace can also use the RegEx values.


Adding on to Brian Schmitt's answer...

Regular expression searches using \n work as expected. However you have to be a little careful when using \n in regex replaces with Visual Studio 2008. For example, if you search for \n and replace with \n (yes, the exact same thing) all of the line breaks in your file(s) will be converted to Unix-style newlines (LF). This may be a bug in Visual Studio. I find it hard to believe this is the intended functionality.

To get around this, you can use tagged expressions, using curly braces: e.g. search for SearchValue{\n} and replace with ReplaceValue\1. This ensures that the same line-break character(s) that were found when searching will also be used when replacing.


You can try my Multiline Search and Replace Macro.

0

精彩评论

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

关注公众号