KnowDotNet

VB.NET Control Characters

by William Ryan

Just about anything that can be done in .NET, can be done a few different ways.  Like everything else, there are usually trade-offs to using one methodology over another.  Anyway, when you want to insert some special characters  likeCrLf (CarriageReturn|LineFeed) VisualBasic .NET provides you an excellent mechanism for doing so.

I've seen many <=VB6 programmers point out that you can still use the old school constants like vbCrLf
and the like.  However, those constants are part of the compatibilty library and may well be deprecated in future additions of .NET.  Moreoever, some of the older methods Chr(10) + Chr(13) lack clarity and provide no visible benefit.

Anyway, the truly .NET way to create a CarriageReturn|LineFeed is to use Environment.NewLine but many other characters aren't present in the Environment namespace.

Enough talk, here they are:


VB.NET Value                         Unicode Value               Description

ControlChars.Cr                      x000D                       Carriage Return
ControlChars.Lf                      x000A                       Line Feed
ControlChars.CrLf                    x000D & x000A               Carriage Return|Line Feed
ControlChars.NewLine                 x000D & x000A               "        "
ControlChars.Tab                     x0009                       Tab
ControlChars.Quote                   x0022                       Quotation Mark
ControlChars.Back                    x0008                       BackSpace
ControlChars.NullChar                x0000                       0



So, if you want to use any of these features employing the '.NET' method, they are clear and easy to use.  Moreover, if you don't like the verbosity, you can declare a Constant setting it to them, and use the constant as a replacement:

Const a as String = "ControlChars.CrLf"

Dim FistName as String = "William" & a
Dim LastName as String = "Ryan" & a
Dim FullName as String = "William Ryan" & a


This code yields the same results as substituting a with
ControlChars.CrLf and/or vbCrLf.

Obviously this abbreviation defeats the purpose of increased clarity, but my point was just to illustrate how it would work.