Skip to content

Instantly share code, notes, and snippets.

@huyderman
Created March 16, 2012 13:20
Show Gist options
  • Save huyderman/2050039 to your computer and use it in GitHub Desktop.
Save huyderman/2050039 to your computer and use it in GitHub Desktop.
C# Normalize Newline
using System.Text.RegularExpressions;
public static class StringHelpers {
private const char _cr = '\u000D';
private const char _lf = '\u000A';
private const string _crlf = _cr + _lf;
private static Regex _crlfRegex = new Regex(_cr + '|' + _lf + '|' + _crlf);
public static string NormalizeNewline(this string str){
return _crlfRegex.Replace(str, "\n");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment