Add line numbers to text
public void ConvertText()
{
StringBuilder output = new StringBuilder();
try
{
char[] end_of_line = {(char)10};
string[] lines = this.Text.Split( end_of_line );
int line_count = lines.GetUpperBound(0)+1;
int linenumber_max_width = line_count.ToString().Length;
string padding = new String( ' ', this.LineNumberPaddingWidth);
for ( int i=0; i<line_count; i++ )
{
output.Append( this.GetFormattedLineNumber( i+1,
linenumber_max_width, padding ) );
output.Append( lines[i] );
output.Append( "\r\n" );
}
if ( this.ConvertTabsToSpaces )
{
string spaces = new String( ' ', this.TabToSpacesWidth);
output = output.Replace( "\t", spaces );
}
}
catch ( Exception e )
{
output.Append( e.Message );
}
this.Text = output.ToString();
}