Results 1 to 12 of 12

Thread: Equivalent vbCrLF in C#

  1. #1

    Thread Starter
    Member
    Join Date
    Sep 2002
    Location
    London
    Posts
    63

    Equivalent vbCrLF in C#

    is there an equivelent in C#

    I want to write to a textbox and add empty lines in between words.

    In VB I could just do:

    txtTextBox = "Name " & vbCrLF

    in C#, i'm currently doing:

    txtTextBox = "Name " + (char)13 + (char)10;

    there must be something in C#

  2. #2
    Lively Member
    Join Date
    Nov 2001
    Location
    fl
    Posts
    92
    \r\n

  3. #3
    PowerPoster sunburnt's Avatar
    Join Date
    Feb 2001
    Location
    Boulder, Colorado
    Posts
    1,403
    also Environment.NewLineString or something to that effect.
    Every passing hour brings the Solar System forty-three thousand miles closer to Globular Cluster M13 in Hercules -- and still there are some misfits who insist that there is no such thing as progress.

  4. #4
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    But XfoxX's approach is the standard one:
    Code:
    "Name\r\n"
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  5. #5

    Thread Starter
    Member
    Join Date
    Sep 2002
    Location
    London
    Posts
    63
    Thanks.

    "\r\n" worked fine.

  6. #6
    PowerPoster sunburnt's Avatar
    Join Date
    Feb 2001
    Location
    Boulder, Colorado
    Posts
    1,403
    It may be the standard approach, but if you're a "OMG Multiplatform .NET!!!!" Nazi, you'd use the Envirionment.NewLine variable.

    ....


    Yeah, I use \r\n too.
    Every passing hour brings the Solar System forty-three thousand miles closer to Globular Cluster M13 in Hercules -- and still there are some misfits who insist that there is no such thing as progress.

  7. #7
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Yeah, you're right.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  8. #8
    Junior Member
    Join Date
    Mar 2001
    Posts
    25
    ok. then I have a follow up question.
    If I have a big long string that I read from a file, and I want to split it into an array of lines, I use the following:
    [code]
    System.IO.StreamReader reader = System.IO.File.OpenText("c:\\directory\\filename.txt");
    string wholeText = reader.ReadToEnd();
    string[] textArray = wholeText.Split('\n');
    [code]

    This leaves me with an array of strings, but each one has a '\r' at the end. If I try to split on Environment.NewLineString then it yells at me for supplying a string instead of a char[]. So I use Environment.NewLineString.ToCharArray(). Since it finds both delimiters right next to each other, it gives an emptry string between each line in the array. What would be the proper way to split on the whole carriage return\line feed instead of just part of it?

  9. #9
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Split at \n and trim away the \r.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  10. #10
    Junior Member
    Join Date
    Mar 2001
    Posts
    25
    That's what I'm doing now, I just don't really like it. It seems like there should be a cleaner way.

  11. #11
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Sure there is: write your own split function.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  12. #12
    Junior Member
    Join Date
    Mar 2001
    Posts
    25
    Ah-ha! Something (marginally) cleaner than trimming off the '\r' at the end of each element of the array. Before I do the split, I do this:

    wholeText = wholeText.Replace("\r", "");

    Then the split does it all neat and tidy like I want.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width