December 2001
Intermediate to advanced
416 pages
8h 16m
English
In addition to writing each line of text to the output file, let's extend the previous code segment to also write the line to the user's console. When writing to the console, however, we want to indicate the line number and the length of the line in characters, as well as the text itself. In addition, we don't want to echo an empty line. Here is the relevant portion of the modified code segment:
string text_line; int line_cnt = 1; while (( text_line = freader.ReadLine() ) != null ) { // don't format empty lines if ( text_line.Length == 0 ) { Console.WriteLine(); continue; } // format output to console: // 1 (42): Master Timothy Gnome left home one morning Console.WriteLine( "{0} ({2}): {1}", line_cnt++, text_line, text_line.Length ...Read now
Unlock full access