After searching the web and reading docs on MSDN, I couldn't find any examples of how to replicate a tab character in C#. I was going to post a question here when I finally figured it out...
I'm sure it is obvious to those fluent in C#, but there were SO many similar questions in various forums, I thought an example was worth posting (for those still learning C# like me). Key points:
string
char
\t
in a string is converted to a tab: "John\tSmith"
'\t'
by itself is like a tab constHere is some code to add tabs to the front of an HTML line, and end it with a newline:
public static string FormatHTMLLine(int Indent, string Value)
{
return new string('\t', Indent) + Value + "\n";
}
You could also use:
string s = new string('\t', Indent);
Is this the most efficient way to replicate tabs in C#? Since I'm not yet 'fluent', I would appreciate any pointers.
Yes, I think this is the best way.
The string constructor you are using constructs a string containing the character you specify as the first argument repeated count
times, where count
is the second argument.