Inserting a tab character into text using C#


I'm building an application where I should capture several values and build a text with them: Name, Age, etc.

The output will be a plain text into a TextBox.

I am trying to make those information appear in kind of columns, therefore I am trying to separate them with tab to make it clearer.

For example, instead of having:

Ann 26
Sarah 29
Paul 45

I would like it to show as:

Ann tab 26 Sarah tab 29 Paul tab 45

Any tip on how to insert the tabs into my text?

7/23/2015 1:51:21 PM

Accepted Answer

Try using the \t character in your strings

1/31/2012 12:50:46 PM

Hazar is right with his \t. Here's the full list of escape characters for C#:

\' for a single quote.

\" for a double quote.

\\ for a backslash.

\0 for a null character.

\a for an alert character.

\b for a backspace.

\f for a form feed.

\n for a new line.

\r for a carriage return.

\t for a horizontal tab.

\v for a vertical tab.

\uxxxx for a unicode character hex value (e.g. \u0020).

\x is the same as \u, but you don't need leading zeroes (e.g. \x20).

\Uxxxxxxxx for a unicode character hex value (longer form needed for generating surrogates).

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow