Generating an indented string for a single line of text

You can create your indention with this:

var indent = new string(' ', indentLevel * IndentSize);

IndentSize would be a constant with value 4 or 8.


I would probably do something like this to add Indent.

public static string Indent(int count)
{
    return "".PadLeft(count);
}

To use it you can do the following:

Indent(4) + "My Random Text"

In your application you could simply do:

s.Write(Indent(indentLevel));

or

s.Write("".PadLeft(indentLevel));

It comes in the box!

Use System.CodeDom.Compiler.IndentedTextWriter.