Answer to Question #272759 in C# for Holik

Question #272759

11. File components-strings. Determine the number of characters in each line.

1
Expert's answer
2021-11-29T10:32:04-0500
using System;
using System.Collections.Generic;
using System.IO;


namespace App
{
    class Program
    {




        public static void Main()
        {




            Console.Write("Enter the file name: ");
            string fileName = Console.ReadLine();
            //string path = @"c:\temp\MyTest.txt";
            if (File.Exists(fileName))
            {
                // Open the file to read from.
                string[] readText = File.ReadAllLines(fileName);
                int counterLine = 1;
                foreach (string s in readText)
                {
                    Console.WriteLine("The number of characters in line {0} is {1}", counterLine, s.Length);
                    counterLine++;
                }
            }
            Console.ReadLine();
        }


    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS