When you open a file with mixed line endings, Visual Studio will prompt you to normalize it. Is there a way to normalize all files in the current solution?
Related posts that don't answer my question:
As yellowblood pointed out in Aaron F.'s answer, if you replace \n
(LF) with \r\n
(CRLF), you will have a bad time since it will add a CR before every LF, even those that already had one.
However, what you want can be achieved with regular expressions using any text editor that supports batch replacing in files (like Notepad++ or Visual Studio's "Replace in Files").
For example, to replace LF with CRLF, make sure to activate the regex option then replace all occurences of
(?<!\r)\n
with
\r\n
\r
is a carriage return (CR), \n
is a line feed (LF). The pattern (?<!\r)\n
will match any line feed whose previous character is not a carriage return, without capturing (i.e. replacing) that previous character.
The other way around is much simpler: simply replace \r\n
with \n
.
As always, back up your files and make sure to test the operation on a single file before processing the whole solution.
I would have added this as a comment to Aaron F.'s answer but my reputation isn't high enough :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With