End of line id in VB.NET?

What final line identifier should I use (for example, for output to text files)?

There are many options:

  • vbCrLf
  • vbNewLine (apparently the alias vbCrLf)
  • ControlChars.CrLf
  • ControlChars.NewLine
  • Environment.NewLine
  • Static member in some C # class in the application (solution in a mixed language is required): public static string LINEEND = "\ r \ n";
  • Global.Microsoft.VisualBasic.ChrW(13) & Global.Microsoft.VisualBasic.ChrW(10) (created by Visual Studio designer, at least Visual Basic 2005 Express Edition , for TextBox with Multiline property set to True when Shift + Return is used when editing the Text property.)

What is the best practice?

+16
Sep 09 '09 at 12:03
source share
3 answers

I believe that in general it makes sense to use Environment.NewLine as a newline identifier for a number of reasons:

  • This is an environment dependent variable . If you, for example, run your program on Linux (for example), then the value will be just \n .
  • vbCrLf is an obsolete constant from VB6 and earlier languages. In addition, it is not independent of the environment.
  • \r\n has the same problem as it is environment-independent, and also cannot be performed well in VB.NET (you need to assign the variable Chr(13) & Chr(10) ).
  • The controls exist in the Microsoft.VisualBasic namespace, which makes it compatible with the previous version, for example vbCrLf . Always avoid legacy code if possible.
+23
Sep 09 '09 at 12:08
source share

Environment.NewLine simply because it depends on the environment and behaves differently on different platforms.

+5
Sep 09 '09 at 12:11
source share

Depending on the programming style, you can choose:

  • The ControlChars class, if you always use VB and other parts of your code, use VB standards (how do you declare variables? Like Integer or As Int32? Integer is VB, Int32 is common for every .NET language). In any case, only if you have already married VB. Otherwise..
  • An environment for common, language and environment independently (my suggestion)

I think the worst thing would be to use retro-resistance functions like vbCrLf (or CInt (), etc.)

+2
Sep 09 '09 at 12:14
source share



All Articles