1

Trying to use StreamReader or similar from C# to read and write VERY LONG lines without the linebreak.

As I understand it, linebreak is still just 2 bytes (CR+LF) in a long bytearray called a file. At least thats how I am used to it in C/C++...

Is this the same for C# and .net or is there some maximum length for lines without a linebreak?

BerggreenDK
  • 4,915
  • 9
  • 39
  • 61
  • If you want it to be cross-platform, you should use Environment.NewLine, as Unix uses LF only. – jb. Oct 09 '11 at 20:12
  • @jb. : C# isn't intended to be cross-platform... just because mono exists it doesn't mean everyone use, should write cross platform code, or even be aware of that. if he mentioned cross platform in his question then this would be a good comment. – Daniel Oct 10 '11 at 04:09
  • C# and .NET were /definitely/ designed to be cross-platform. Whether one should or should not write cross-platform code is up to them. – Mike Christensen Oct 10 '11 at 04:14
  • @Dani I mentioned it because he says `linebreak is still just 2 bytes (CR+LF)`. And that's not true if you're on unix. I just didn't want him to write a big program then have it fail in weird ways because he didn't anticipate LF-only endings. – jb. Oct 10 '11 at 05:35
  • @MikeChristensen: Why do you think that? Why would Microsoft design a cross platform language? – Daniel Oct 10 '11 at 05:38
  • Well, 1) There's many .NET framework hooks such as the Environment class that can abstract environmental differences. 2) Microsoft gave up control of the CLS to ECMA purposely to promote an open platform (Unlike Sun), 3) Microsoft open-sourced sample compilers and runtimes to encourage cross-platform support, 4) IL is designed to be CPU agnostic, 5) Microsoft brought in dozens of universities and other standards bodies while designing the framework and compilers. – Mike Christensen Oct 10 '11 at 05:45

1 Answers1

6

There are no specific limitations in .NET, but different ways of viewing long lines may give you problems, mostly related to performance. Try to open your long line file in notepad with word wrap on and it will choke on you. The same with multiline textboxes in .NET.

But for pure programmatic reading very long lines is no problem.

Albin Sunnanbo
  • 46,430
  • 8
  • 69
  • 108
  • Great! I only want to use it as a quick way of storing a lot of plain data before it goes into SQL format. For a lazy/late parsing that is. This is great news! thanks for quick response! – BerggreenDK Oct 09 '11 at 20:10
  • 4
    Well, strings (and buffers) are limited to 2GB, but that's usually not a practical problem. – H H Oct 09 '11 at 20:11