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 6231757
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T09:59:26+00:00 2026-05-24T09:59:26+00:00

Im reading file in as a stream: Stream fin = File.OpenRead(FilePath); Is there any

  • 0

Im reading file in as a stream: Stream fin = File.OpenRead(FilePath);
Is there any way how i would be able to find and remove all carriage returns from that file stream?

EDIT: The goal is to remove single carriage-returns \r and leave the carriage returns what are with newline "\r\n" intact.

Example file:

The key backed up in this file is:\r
\r\n
pub   2048R/65079BB4 2011-08-01\r
\r\n
      Key fingerprint = 2342334234\r
\r\n
uid                  test\r
\r\n
sub   2048R/0B917D1C 2011-08-01\r

And the result should look like:

The key backed up in this file is:
\r\n
pub   2048R/65079BB4 2011-08-01
\r\n
      Key fingerprint = 2342334234
\r\n
uid                  test
\r\n
sub   2048R/0B917D1C 2011-08-01

EDIT2: The final solution what is working looks like this:

    static private Stream RemoveExtraCarriageReturns(Stream streamIn)
    {
        StreamReader reader = new StreamReader(streamIn);
        string key = reader.ReadToEnd();
        string final = key.Replace("\r\r", "\r");
        byte[] array = Encoding.ASCII.GetBytes(final);
        MemoryStream stream = new MemoryStream(array);
        return stream;
    }

I take in the Stream use StreamReader to read it into a string, then remove the extra carriage-return and write it back to a Stream.
Does my code look ok or should i do something differently?

  • 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. Editorial Team
    Editorial Team
    2026-05-24T09:59:26+00:00Added an answer on May 24, 2026 at 9:59 am

    After looking at your sample text, the following will remove your single ‘r’ instances:

    string text = File.ReadAllText(FilePath);
    
    text = text.Replace("\r\r", "\r");
    
    File.WriteAllText(FilePath + ".modified", text);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Are there any good configuration file reading libraries for C\C++ that can be used
In a node program I'm reading from a file stream with fs.createReadStream . But
I need an input file stream which would have a bidirectional iterator/adapter. Unfortunately std::ifstream
From my understanding, ReadAllLines would open a file, and then return all the lines
With the following file reading code: using (FileStream fileStream = new FileStream(fileName, FileMode.Open, FileAccess.Read,
Typical approaches recommend reading the binary via FileStream and comparing it byte-by-byte. Would a
i just create reading file feature. In general, what kind PHP class that usually
I am Reading Excel File in .Net Framework 1.1 , using C# . I
While implementing XML file reading/writing in my application I saw that when I call
I'm reading a file using bufferedreader, so lets say i have line = br.readLine();

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.