Re: how to check CRLF in C#

Discussion in 'ASP .Net' started by Kevin Spencer, Aug 25, 2003.

  1. 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" <> wrote in message
    news:...
    > 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
    >
    >
    Kevin Spencer, Aug 25, 2003
    #1
    1. Advertising

  2. 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" <> wrote in message
    news:...
    > 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" <> wrote in message
    > news:...
    > > 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)
    > > {
    > > case '\r':
    > > retVal.Append("<BR>");
    > > break;
    > > default:
    > > retVal.Append(BodyText);
    > > break;
    > > }
    > > }
    > > }
    > > return retVal.ToString();
    > > }
    > >
    > >
    > > *** Sent via Developersdex http://www.developersdex.com ***
    > > Don't just participate in USENET...get rewarded for it!

    >
    >
    Kevin Spencer, Aug 26, 2003
    #2
    1. Advertising

  3. 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" <> wrote in message
    news:e%23Ur9A$...
    > Kevin that depends, the original question was how to replace CRLF pairs,

    not
    > platform specific new line character(s).
    >
    > Jerry
    >
    > "Kevin Spencer" <> wrote in message
    > news:...
    > > 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" <> wrote in message
    > > news:...
    > > > 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" <> wrote in message
    > > > news:...
    > > > > 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)
    > > > > {
    > > > > case '\r':
    > > > > retVal.Append("<BR>");
    > > > > break;
    > > > > default:
    > > > > retVal.Append(BodyText);
    > > > > break;
    > > > > }
    > > > > }
    > > > > }
    > > > > return retVal.ToString();
    > > > > }
    > > > >
    > > > >
    > > > > *** Sent via Developersdex http://www.developersdex.com ***
    > > > > Don't just participate in USENET...get rewarded for it!
    > > >
    > > >

    > >
    > >

    >
    >
    Kevin Spencer, Aug 26, 2003
    #3
  4. Kevin Spencer

    Jerry III Guest

    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" <> wrote in message
    news:OaMJUj$...
    > 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" <> wrote in message
    > news:e%23Ur9A$...
    > > Kevin that depends, the original question was how to replace CRLF pairs,

    > not
    > > platform specific new line character(s).
    > >
    > > Jerry
    > >
    > > "Kevin Spencer" <> wrote in message
    > > news:...
    > > > 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" <> wrote in message
    > > > news:...
    > > > > 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" <> wrote in message
    > > > > news:...
    > > > > > 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)
    > > > > > {
    > > > > > case '\r':
    > > > > > retVal.Append("<BR>");
    > > > > > break;
    > > > > > default:
    > > > > > retVal.Append(BodyText);
    > > > > > break;
    > > > > > }
    > > > > > }
    > > > > > }
    > > > > > return retVal.ToString();
    > > > > > }
    > > > > >
    > > > > >
    > > > > > *** Sent via Developersdex http://www.developersdex.com ***
    > > > > > Don't just participate in USENET...get rewarded for it!
    > > > >
    > > > >
    > > >
    > > >

    > >
    > >

    >
    >
    Jerry III, Aug 27, 2003
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jerry III

    Re: how to check CRLF in C#

    Jerry III, Aug 25, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    790
    Jerry III
    Aug 25, 2003
  2. Simon Chung-Jen Chuang

    Re: how to check CRLF in C#

    Simon Chung-Jen Chuang, Aug 26, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    417
    Simon Chung-Jen Chuang
    Aug 26, 2003
  3. Jack Wright

    Problem in CRLF in multiline fields

    Jack Wright, Apr 20, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    392
    Jack Wright
    Apr 21, 2004
  4. Michael Persaud

    CRLF How does it work for asp.net???!!

    Michael Persaud, May 27, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    5,902
    Michael Persaud
    May 27, 2004
  5. Andrew

    ASCII file without crlf's

    Andrew, Jun 21, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    418
    M. Zeeshan Mustafa
    Jun 22, 2004
Loading...

Share This Page