Find and replace - Add carriage return OR Newline
If you set Use regular expressions
flag then the \n
character would be translated. But keep in mind that you would have to modify your search term to be regexp friendly. In your case it should be escaped like this \~\~\?
.
Make sure Use: Regular expressions
is selected in the Find and Replace
dialog:
Note that for Visual Studio 2010, this doesn't work in the Visual Studio Productivity Power Tools' Quick Find
extension (as of the July 2011 update); instead, you'll need to use the full Find and Replace
dialog (use Ctrl+Shift+H
, or Edit --> Find and Replace --> Replace in Files
), and change the scope to Current Document
.
You can also try \x0d\x0a
in the "Replace with" box with "Use regular Expression" box checked to get carriage return + line feed using Visual Studio Find/Replace.
Using \n
(line feed) is the same as \x0a
If you want to avoid the hassle of escaping the special characters in your search and replacement string when using regular expressions, do the following steps:
- Search for your original string, and replace it with "UniqueString42", with regular expressions off.
- Search for "UniqueString42" and replace it with "UniqueString42\nUniqueString1337", with regular expressions on
- Search for "UniqueString42" and replace it with the first line of your replacement (often your original string), with regular expressions off.
- Search for "UniqueString42" and replace it with the second line of your replacement, with regular expressions off.
Note that even if you want to manually pich matches for the first search and replace, you can safely use "replace all" for the three last steps.
Example
For example, if you want to replace this:
public IFoo SomeField { get { return this.SomeField; } }
with that:
public IFoo Foo { get { return this.MyFoo; } }
public IBar Bar { get { return this.MyBar; } }
You would do the following substitutions:
public IFoo SomeField { get { return this.SomeField; } }
→XOXOXOXO
(regex off).XOXOXOXO
→XOXOXOXO\nHUHUHUHU
(regex on).XOXOXOXO
→public IFoo Foo { get { return this.MyFoo; } }
(regex off).HUHUHUHU
→public IFoo Bar { get { return this.MyBar; } }
(regex off).