replace string with a newline in emacs

This might help fellow Emacs users needing to replace a given string with a new string containing a newline.

I wanted to split a very long list of semicolon separated JARs to insert them in a Java manifest file to get around the dreaded "Input line too long" problem on Windows.

What I wanted to do was to M-x replace-string ; ENTER with a newline and a space. Here lies the problem, the replace-string command rightfully interprets ENTER to mean that the replacement string has been entered, and not to mean that it should substitute with a newline.

The solution is to type C-q C-j at the replace with: prompt. C-q runs the quoted-insert command, while C-j runs the newline-and-indent command.

Another way to achieve the same result is to go to the end of a line followed by another line and kill the newline (i.e. C-e, C-k), then just yank it back at the replace-string with: prompt (C-y).