Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 50143
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T16:32:50+00:00 2026-05-10T16:32:50+00:00

I have a data stream that may contain \r, \n, \r\n, \n\r or any

  • 0

I have a data stream that may contain \r, \n, \r\n, \n\r or any combination of them. Is there a simple way to normalize the data to make all of them simply become \r\n pairs to make display more consistent?

So something that would yield this kind of translation table:

\r     --> \r\n \n     --> \r\n \n\n   --> \r\n\r\n \n\r   --> \r\n \r\n   --> \r\n \r\n\n --> \r\n\r\n 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T16:32:50+00:00Added an answer on May 10, 2026 at 4:32 pm

    I believe this will do what you need:

    using System.Text.RegularExpressions; // ... string normalized = Regex.Replace(originalString, @"\r\n|\n\r|\n|\r", "\r\n"); 

    I’m not 100% sure on the exact syntax, and I don’t have a .Net compiler handy to check. I wrote it in perl, and converted it into (hopefully correct) C#. The only real trick is to match "\r\n" and "\n\r" first.

    To apply it to an entire stream, just run it on chunks of input. (You could do this with a stream wrapper if you want.)


    The original perl:

    $str =~ s/\r\n|\n\r|\n|\r/\r\n/g; 

    The test results:

    [bash$] ./test.pl \r -> \r\n \n -> \r\n \n\n -> \r\n\r\n \n\r -> \r\n \r\n -> \r\n \r\n\n -> \r\n\r\n 

    Update: Now converts \n\r to \r\n, though I wouldn’t call that normalization.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a byte stream that may be UTF-8 data or it may be
I have a stream of data that I want to place into a container.
I often run into the problem that I have one stream full of data
I have a message object serialized as binary data stream (it can be any
I have an application that streams through 250 MB of data, applying a simple
I'm considering the following: I have some data stream which I'd like to protect
I am in a Windows Desktop application and I have a data stream and
I have a DirectShow source filter for receiving a Network stream containing RFC2435 data
I have a response which may return text/html or application/octet-stream . If I receive
Assume that I have some array of data (a vector to be specific). Can

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.