-
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#
-
-
also Environment.NewLineString or something to that effect.
-
But XfoxX's approach is the standard one:
-
Thanks.
"\r\n" worked fine.
-
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. :rolleyes:
-
-
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?
-
Split at \n and trim away the \r.
-
That's what I'm doing now, I just don't really like it. It seems like there should be a cleaner way.
-
Sure there is: write your own split function.
-
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.