222
54
Consider the scenario where you have a specific string that you want to find-and-replace. You want to replace it with a new string that contains a newline character (or character sequence).
abc123 xyz456-blah
fsafd23 xyz456-green
89hjkf23 xyz456-red
afdsa23 xyz456-yellow
abaac123 xyz456-orange
In the scenario above, I'd like to find " xyz
" and replace the space with a carriage return/newline.
The results would look like:
abc123
xyz456-blah
fsafd23
xyz456-green
89hjkf23
xyz456-red
︙
etc...
Question: How would you most easily achieve this using Notepad++? Are there any other tools that you'd suggest to easily perform this command?
@goku_da_master +1 that was exactly what i was trying to figure out. Thought maybe there was a different way but this works just fine =-) – Mungoid – 2014-09-13T21:11:15.953
How do I do this the other way around? I want to replace things like newlines with text. – Aaron Franke – 2016-12-12T17:00:54.087
This also works in reverse. I just used replace
</item>\r\n <item>
with<\item>\r\n\r\n <item>
in N++ reading an xml document to add an empty line between each item, visually separating it and making it easier to read. – Isaac Reefman – 2018-06-21T00:53:09.060\r\n didn't work for me, but \r did surprisingly. NP++ v 7.75. I was trying to replace ";" with carriage return. – Vinay – 2018-07-27T18:44:44.043
3Your phrase "more conventional" is misleading. "\r\n" is the standard on Windows. It's just that a lot of editors and IDEs happen to recognize the Unix/Linux standard line ending "\n" and display the document accordingly. There's nothing about "\n" that makes it more conventional. – Brian Lacy – 2010-11-12T20:44:03.333
To be honest, the Win/DOS version makes more sense to me. "\r" means "Carriage Return, or 'Return the carriage/cursor to the beginning of the line'" and "\n" means "Advance the carriage/cursor forward one line". Of course, Unix came 20 years before, so I guess in that sense it is Microsoft who broke the standard. – Brian Lacy – 2010-11-12T20:49:05.447
2\r\n = Windows newline syntax. However, for everything other than plain old notepad, it will accept just \n for a newline (which is also more conventional). – Macha – 2009-09-02T18:09:09.747
7
this wont work unless you set the search mode, as specified in the other answer: http://superuser.com/questions/34451/notepad-find-and-replace-string-with-a-new-line/34454#34454
– codeulike – 2011-08-19T15:49:51.3007If you're trying to replace the literal string "\r\n" with an actual new line I had to do the following: set search mode to normal, find/replace \r\n with ***. Then set search mode to Extended, find/replace *** with \r\n. – goku_da_master – 2014-05-28T17:38:15.407