tags:

views:

196

answers:

3

Is there a way to use a tab character like a new line character inside Environment class, instead of using "\t"?

+17  A: 

No.

The only reason that Environment.NewLine exists at all is cross-platform issues, which the tab character doesn't have.
The newline character is \r on (Pre-OS X) Mac, \n on UNIX, and \r\n on Windows.
To allow .Net code to be portable across these platforms, the Environment.NewLine property was created, to return the newline character(s) used by the platform your code is running on.

The tab character is standard across all platforms, so there's no point in making a property to return it.

SLaks
But it would be useful to have a property that returns how many spaces a tab equates to. In my Environment (within four feet of my desk), a tab equals four spaces ;)
RedFilter
@OrbMan: That's an editor setting. It would be meaningless to have that as a framework property.
SLaks
Pedantry, but Mac OS X (and thus all Macs installed after 2001 or thereabout) uses `\n`.
calmh
TAB character does not contain spaces. Count of equal space characters depends only on word processors settings.
Anton
You're a humourless bunch.
RedFilter
@OrbMan: I had been wondering whether you were serious.
SLaks
I **do** like the idea of having a personal Environment wherever I go. Any device within a few meters of me should use it for localization when I access said device. Consider this prior art.
RedFilter
+2  A: 

If you really wanted to you, you could add a reference and use Microsoft.VisualBasic.Constants.vbTab. But the tab character is not something that changes based on your environment so System.Environment wouldn't have a property for you.

Ken Browning
+1  A: 

Are you looking for a pre-defined system constant for this (like Environment.NewLine)? There is no such thing as far as I know, but you could certainly create your own constant.

Ray
Yeah that was what I was looking for.
Joan Venge
@Joan: __Why__?
SLaks
I assumed it was the same value for every platform but thought, sort of like since the tab character seems widely used, it might be "better" to have it as a constant property. I see code with "\t" all over all the time so thought it would be cool to have a default defined constant.
Joan Venge
@Joan: On the contrary. `"a\tb"` is much nicer than `"a" + Environment.HorizontalTab + "b"`.
SLaks
I would suggest creating a constant named for its usage, rather than its content. Since a tab character is often used as a field separator, I would create a constant like 'const string Separator = "\t"'. Then if I need to change the separator to "|" or ",", no problem, since I didn't name it HorizontalTab or something content-specific.
Ray