What is the best way to generate an indented line from space characters. I mean something similar to this:
string indent = String.Join(" ", new String[indentlevel]);
s.Write(indent + "My 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));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With