Meziantou
Read post

New lines are more than \r and \n

Most developers only handle \r\n and \n as line endings, but Unicode defines additional newline characters including NEL (\u0085), Line Separator (\u2028), Paragraph Separator (\u2029), Vertical Tab (\v), and Form Feed (\f). These can appear in user input, office-copied text, or cross-platform data and cause silent parsing bugs. In .NET, safer line splitting can be done with a Regex pattern covering all Unicode newlines, or using Regex.EnumerateSplits (allocation-free, .NET 9+). The built-in string.ReplaceLineEndings normalizes all variants to a single convention. TextReader.ReadLine() only handles the three classic terminators and may not be sufficient for all scenarios.

    #.net#c#
Jun 15•4m read time•From meziantou.net
Post cover image
Table of contents
# The line breaks you should know# Why this matters in real code# Safer parsing in .NET# Additional resources
534 Impressions
Meziantou's image
Meziantou

Meziantou's resource offers insights, tutorials, and resources for software developers and IT profes...

18 Followers

•

104 Upvotes

Would you recommend this post?

Copy link
WhatsApp
Facebook
X
New Squad
  • © 2026 Daily Dev Ltd.
  • Guidelines
  • Explore
  • Tags
  • Sources
  • Squads
  • Leaderboard