0

I found vbCrLf has it's analogue (or copy) in Environment namespace in VB.net. As I understood there is no difference between them except vbCrLf is harder for reading when Environment.NewLine is clear.

But I can't find any comfortable analogue of vbCr in Environment. I checked all the methods but still can't find.

Is there any comfortable for reading analogue of vbCr in VB.net?

P.S. Why they create analogue for new line symbol but forget about this one?

Mikhail_Sam
  • 10,602
  • 11
  • 66
  • 102
  • 2
    I can't really answer why they did not create an analogue for `vbCr`, but...why bother? you can just add something like `Const CarriageReturn As Char = Chr(13)` – Pikoh Mar 31 '17 at 07:36

1 Answers1

2

Why they create analogue for new line symbol but forget about this one?

They did not create an analogue for the new line symbol.

The Environment.NewLine is platform-dependent and will be different on different platforms. You use it e.g. when you want to generate human-readable text and therefore want the "whatever the newline symbol is, I don't care what it is exactly".

The vbCrLf is not platform-dependent, it's \r\n on all platforms. You use that when you are dealing with data contracts that specify there must be an \r\n (e.g. forming or reading HTTP headers, these are separated with \r\n).

They are not interchangeable and you are supposed to pick the one that is correct for the given purpose.

Personally I like how vbCrLf and vbCr look and have no problems with them. If you think otherwise, you can confuse future readers of your code by defining custom constants named the way you like.

Community
  • 1
  • 1
GSerg
  • 76,472
  • 17
  • 159
  • 346