How can I replace all types of line breaks (CR, LF and CrLf) using Regex?
I´ve tried different combinations of “\n” and “\r” but none finds them all.
formatedString = System.Text.RegularExpressions.Regex.Replace(text, "\r\n", "[Exp 1]")
The following code does the job but it bugs me that I can´t seem to replace the Line Feed using Regexp.
formatedString = formatedString.Replace(Environment.NewLine, "[Environment.NewLine]") ' Equals CR
formatedString = formatedString.Replace(ControlChars.CrLf, "[ControlChars.CrLf]") ' CR and LF
formatedString = formatedString.Replace(ControlChars.Cr, "[ControlChars.Cr]") ' Carriage Return (CR)
formatedString = formatedString.Replace(ControlChars.Lf, "[ControlChars.Lf]") ' Line Feed (LF)
All advices are most welcome! 🙂
\r,\nand\r\nshould cover all cases of linebreaks.\n\ris not used by any system (that I know of…)In VB, if not using regexes, you could replace all:
with whatever line ending you prefer (obviously you can omit the preferred one from the list of “newline/cr” characters you replace)