Comments For Entry #810

Convert Unix Linefeeds To DOS C#(Comments RSS)

Googled around for a quick way to fix line feeds in a string on a Windows computer and found all sorts of silly suggestions (converting all Windows line feeds to Unix, then Unix to Windows or worse just adding additional \r's to all \n's you see, even if they are already correct Windows linefeeds) when really we could just do it in a regular expression.

Here is my code:

// This will convert any Linux line feeds to Windows line feeds.
private static object CorrectLineFeeds(string message)
{ return Regex.Replace(message, "([^\r])\n", "$1\r\n"); }

Simples!

Add New Comment

Name

E-mail

Homepage

Remember Me           E-mail me replies

Content (HTML not allowed)