Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Re: how to check CRLF in C#

Reply
Thread Tools

Re: how to check CRLF in C#

 
 
Kevin Spencer
Guest
Posts: n/a
 
      08-25-2003
theString.Replace(Environment.NewLine, "<br>")

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
http://www.takempis.com
The more I learn, the less I know.

"Simon Chung-Jen Chuang" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hello,
>
> I want to replace all CRLF(carriage return and line feed) with "<br>" in

C#.
> How should I do?
>
> theString.Replace(?, "<br>");
>
> Thanks,
> Simon
>
>



 
Reply With Quote
 
 
 
 
Kevin Spencer
Guest
Posts: n/a
 
      08-26-2003
It is altogether safer all around to check for Environment.Newline

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
http://www.takempis.com
The more I learn, the less I know.

"Jerry III" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> You do know that Replace method does not update the string but creates a

new
> one (which you have to store and use instead of the original string),

don't
> you? And that your code posted below only replaces carriage returns, not
> CRLF pairs?
>
> Jerry
>
> "Simon Chung-Jen Chuang" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > After my testing, it cannot work. I write a method to do this.
> >
> > public static string Display(string BodyText)
> > {
> > StringBuilder retVal = new StringBuilder();
> > if ((BodyText != null) && (BodyText != String.Empty))
> > {
> > for (int i = 0; i < BodyText.Length; i++)
> > {
> > switch (BodyText[i])
> > {
> > case '\r':
> > retVal.Append("<BR>");
> > break;
> > default:
> > retVal.Append(BodyText[i]);
> > break;
> > }
> > }
> > }
> > return retVal.ToString();
> > }
> >
> >
> > *** Sent via Developersdex http://www.developersdex.com ***
> > Don't just participate in USENET...get rewarded for it!

>
>



 
Reply With Quote
 
 
 
 
Kevin Spencer
Guest
Posts: n/a
 
      08-26-2003
Jerry,

The original message didsn't specify any such thing. The author used "CRLF"
in the title, but obviously didn't know exactly what he was looking for,
other than a method to replace new line character/combination in a string.
Using Environment.Newline will return the correct new line character or
combination for whatever platform one is working on, and is the safest thing
to use. That is what it's for. My advice was correct.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
http://www.takempis.com
The more I learn, the less I know.

"Jerry III" <(E-Mail Removed)> wrote in message
news:e%23Ur9A$(E-Mail Removed)...
> Kevin that depends, the original question was how to replace CRLF pairs,

not
> platform specific new line character(s).
>
> Jerry
>
> "Kevin Spencer" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > It is altogether safer all around to check for Environment.Newline
> >
> > --
> > HTH,
> >
> > Kevin Spencer
> > Microsoft MVP
> > .Net Developer
> > http://www.takempis.com
> > The more I learn, the less I know.
> >
> > "Jerry III" <(E-Mail Removed)> wrote in message
> > news:(E-Mail Removed)...
> > > You do know that Replace method does not update the string but creates

a
> > new
> > > one (which you have to store and use instead of the original string),

> > don't
> > > you? And that your code posted below only replaces carriage returns,

not
> > > CRLF pairs?
> > >
> > > Jerry
> > >
> > > "Simon Chung-Jen Chuang" <(E-Mail Removed)> wrote in message
> > > news:(E-Mail Removed)...
> > > > After my testing, it cannot work. I write a method to do this.
> > > >
> > > > public static string Display(string BodyText)
> > > > {
> > > > StringBuilder retVal = new StringBuilder();
> > > > if ((BodyText != null) && (BodyText != String.Empty))
> > > > {
> > > > for (int i = 0; i < BodyText.Length; i++)
> > > > {
> > > > switch (BodyText[i])
> > > > {
> > > > case '\r':
> > > > retVal.Append("<BR>");
> > > > break;
> > > > default:
> > > > retVal.Append(BodyText[i]);
> > > > break;
> > > > }
> > > > }
> > > > }
> > > > return retVal.ToString();
> > > > }
> > > >
> > > >
> > > > *** Sent via Developersdex http://www.developersdex.com ***
> > > > Don't just participate in USENET...get rewarded for it!
> > >
> > >

> >
> >

>
>



 
Reply With Quote
 
Jerry III
Guest
Posts: n/a
 
      08-27-2003
As long as the files are created on the same platform - you're fine. And
while that's most likely going to be the case there's a chance it won't - a
windows app may read files created by a Unix (or even mainframe, EBCDIC is a
whole new story) app. Or when you move your app from Windows to Linux but
the input files are still going to be created on Windows. So you should
replace whatever your case is, both examples were correct and as I said, it
depends on what exactly are you trying to accomplish.

Jerry

"Kevin Spencer" <(E-Mail Removed)> wrote in message
news:OaMJUj$(E-Mail Removed)...
> Jerry,
>
> The original message didsn't specify any such thing. The author used

"CRLF"
> in the title, but obviously didn't know exactly what he was looking for,
> other than a method to replace new line character/combination in a string.
> Using Environment.Newline will return the correct new line character or
> combination for whatever platform one is working on, and is the safest

thing
> to use. That is what it's for. My advice was correct.
>
> --
> HTH,
>
> Kevin Spencer
> Microsoft MVP
> .Net Developer
> http://www.takempis.com
> The more I learn, the less I know.
>
> "Jerry III" <(E-Mail Removed)> wrote in message
> news:e%23Ur9A$(E-Mail Removed)...
> > Kevin that depends, the original question was how to replace CRLF pairs,

> not
> > platform specific new line character(s).
> >
> > Jerry
> >
> > "Kevin Spencer" <(E-Mail Removed)> wrote in message
> > news:(E-Mail Removed)...
> > > It is altogether safer all around to check for Environment.Newline
> > >
> > > --
> > > HTH,
> > >
> > > Kevin Spencer
> > > Microsoft MVP
> > > .Net Developer
> > > http://www.takempis.com
> > > The more I learn, the less I know.
> > >
> > > "Jerry III" <(E-Mail Removed)> wrote in message
> > > news:(E-Mail Removed)...
> > > > You do know that Replace method does not update the string but

creates
> a
> > > new
> > > > one (which you have to store and use instead of the original

string),
> > > don't
> > > > you? And that your code posted below only replaces carriage returns,

> not
> > > > CRLF pairs?
> > > >
> > > > Jerry
> > > >
> > > > "Simon Chung-Jen Chuang" <(E-Mail Removed)> wrote in message
> > > > news:(E-Mail Removed)...
> > > > > After my testing, it cannot work. I write a method to do this.
> > > > >
> > > > > public static string Display(string BodyText)
> > > > > {
> > > > > StringBuilder retVal = new StringBuilder();
> > > > > if ((BodyText != null) && (BodyText != String.Empty))
> > > > > {
> > > > > for (int i = 0; i < BodyText.Length; i++)
> > > > > {
> > > > > switch (BodyText[i])
> > > > > {
> > > > > case '\r':
> > > > > retVal.Append("<BR>");
> > > > > break;
> > > > > default:
> > > > > retVal.Append(BodyText[i]);
> > > > > break;
> > > > > }
> > > > > }
> > > > > }
> > > > > return retVal.ToString();
> > > > > }
> > > > >
> > > > >
> > > > > *** Sent via Developersdex http://www.developersdex.com ***
> > > > > Don't just participate in USENET...get rewarded for it!
> > > >
> > > >
> > >
> > >

> >
> >

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
ASCII file without crlf's Andrew ASP .Net 2 06-22-2004 11:12 AM
CRLF How does it work for asp.net???!! Michael Persaud ASP .Net 2 05-27-2004 05:11 PM
Problem in CRLF in multiline fields Jack Wright ASP .Net 1 04-21-2004 05:00 AM
Re: how to check CRLF in C# Simon Chung-Jen Chuang ASP .Net 0 08-26-2003 02:54 PM
Re: how to check CRLF in C# Jerry III ASP .Net 0 08-25-2003 07:44 AM



Advertisments