Any simple way to convert Unix LF to DOS CRLF..

cjard

Well-known member
Joined
Apr 25, 2006
Messages
7,081
Programming Experience
10+
..but leave dos CRLF alone?

suppose I have a string that is mixed LF and CRLF. I cant just replace LF with CRLF, because all the existing CRLF become CRCRLF

Going the other way is less of a problem, because CRLF is more specific than LF


So far I envisage either:
Regex find "anything not CR followed by LF" ("[^CR][LF]") replace with CRLF

or:
string.Replace(LF, CRLF).Replace(CRCRLF, CRLF)


Is ther any simple way provided in the framework?

NOTE: here is use e.g CR, i dont mean the string of "C" followed by "R", i mean Chr(13), otherwise noted as <CR> in most places. etc.
 
right off the bat I would simply use:
string.Replace(LF, CRLF).Replace(CRCRLF, CRLF)

until a better method is found
 
Back
Top