Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I insert tabs into strings for a C# console application? [closed]

This console application will write .txt files to disc.

User wants to import these .txt files into Excel such that they are formatted correctly, so I plan to use tabs.

I keep getting this nonsense "Some string /t some other string /t/t some other string". There is no Environment.Tab like there is Environment.NewLine.

How do I get the tabs and not /t into my strings?

I'm sure there's a way and it'll probably be so obvious that I'll have to call myself faint all day on response.

(I'm open to other solutions as well. I might have to use | or some other delimiter/character.)

like image 451
Thomas Avatar asked Jan 06 '13 17:01

Thomas


People also ask

How do I add a tab to a string?

If you use the "\t" escape character once, it adds one tab space in string. This tab character can be used in a string or just directly passed and concatenated with a string and written to console.

How many spaces is a tab?

Generally, a tab is the same width as 4 to 5 spaces provided the font being used equally sizes each character. For example, the Courier font's tab equals 5 spaces, whereas the Arial font is 11 spaces to each tab when the font size for both is set to 12.

How many spaces is a tab in C#?

Sets the distance in spaces between tab stops. The default is four spaces.


2 Answers

Tabs in strings are typically written \t, not /t. Are you escaping your string correctly?

like image 182
Dan Puzey Avatar answered Oct 18 '22 11:10

Dan Puzey


If the purpose is to create text files which will eventually be imported int excel why don't you use comma separated values. More info http://en.wikipedia.org/wiki/Comma-separated_values

like image 38
hmatar Avatar answered Oct 18 '22 12:10

hmatar