Avatar of the_b1ackfox
the_b1ackfox
Flag for United States of America asked on

C# text manipulation of crlf to cr

I need to have my string output with CR's only not CRLF's.  I am using c#.

Hello Experts,  Can one of you help a fox out?  I am reading in a text file (which is full of the CRLF's), I need to create a new file based on the text file and output the result with CR's only  I have tried a lot of methods that don't seem to work, here are my latest two failurs:

//richTextBox1.Text = HL7.Replace("\r\n", "\r");  //.Replace("\r\n", @" \r ");
                    richTextBox1.Text = HL7.Replace("\r\n", @" \r ");

I need a method that takes a string with crlf's and returns a string with cr's only

"help me obi-wan Kenobi, you are my only hope"

Thank you in advance,

Fox
C#

Avatar of undefined
Last Comment
the_b1ackfox

8/22/2022 - Mon
Norie

How are you 'reading' the file?
the_b1ackfox

ASKER
StreamReader SR = new StreamReader(Target);
            while ((line = SR.ReadLine()) != null)
            {
                Ct++;
                Output += Pre + Ct.ToString() + Pre1 + line.Replace("\r\n", "") +Pre2 + "\r";
            }
            SR.Close();
AndyAinscow

That should work.  (The removal of a CRLF and appending a CR at the end of your newly constructed line.)

How do you actually test it is not working?  Your code might function correctly - your testing procedure has the bug.
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
the_b1ackfox

ASKER
I'll copy output into notepad++ and view the outcome
AndyAinscow

That is not a good way to test unless you can view the hex values in your notepad++.  Can you?
the_b1ackfox

ASKER
I can see when the values are removed properly.
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
ASKER CERTIFIED SOLUTION
AndyAinscow

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
SOLUTION
Log in to continue reading
Log In
Sign up - Free for 7 days
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
the_b1ackfox

ASKER
AndyAinscow & Sara,  Thank you both for showing me what I was missing.  Andy, you demonstrated I was on the right path, and Sara you added insight into why I was getting the result I was seeing.  I have thankfully learned something new because of your efforts.