31

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

4
  • What are you missing out with "\t"? Commented Apr 21, 2010 at 21:06
  • 1
    @Oskar: That, I assume, is part of the question. Commented Apr 21, 2010 at 21:07
  • @SLaks, true. Probably he could have written that, although it seems very clear now that you've pointed it out Commented Apr 22, 2010 at 7:36
  • 1
    It's not in Environment but you could use (char)ConsoleKey.Tab Commented Feb 1, 2012 at 23:12

4 Answers 4

50

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.

Sign up to request clarification or add additional context in comments.

7 Comments

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 ;)
@OrbMan: That's an editor setting. It would be meaningless to have that as a framework property.
TAB character does not contain spaces. Count of equal space characters depends only on word processors settings.
You're a humourless bunch.
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.
|
12

You can also use ControlChars.Tab.

2 Comments

Found in the Microsoft.VisualBasic namespace.
Correct answer but not advised....not all implementations of the .Net Fx have the VB library available. Such as the Core implementation only includes the libraries from the System.* namespace.
4

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.

1 Comment

Correct answer but not advised....not all implementations of the .Net Fx have the VB library available. Such as the Core implementation only includes the libraries from the System.* namespace.
1

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.

3 Comments

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: On the contrary. "a\tb" is much nicer than "a" + Environment.HorizontalTab + "b".
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.