Unable to process file

Peter_1985 2,526 Reputation points
2021-03-28T03:38:22.59+00:00

Hi,
Is it too big to process file here,
https://1drv.ms/u/s!Ai8CrEskdewXvk21iZzHnqscSRwt?e=34UcMw

using codes below?

            using (StreamReader sr = new StreamReader(@"e:/inp2.txt", System.Text.Encoding.ASCII))
            {

                while ((line = sr.ReadLine()) != null)
                {
                    //if (line.Trim() == "")
                    //{

                    //}
                    //else
                    {
                        //str.Add(line.Trim().Substring(6));
                        str.Add(line);
                        //str.Add((line+"").Substring(5));
                    }
                }
            }
Windows Forms
Windows Forms
A set of .NET Framework managed libraries for developing graphical user interfaces.
1,839 questions
VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,581 questions
{count} votes

Accepted answer
  1. Viorel 112.7K Reputation points
    2021-03-28T09:22:50.337+00:00

    If the file is large, you cannot load it to memory, but often you can process it line-by-line.

    For example, the next code counts the number of lines:

    long count = 0;
    
    foreach( string line in File.ReadLines( @"...path...", Encoding.ASCII ) )
    {
       // TODO: process 'line' variable
       // . . .
       ++count;
    }
    
    Console.WriteLine( "Total lines: {0:#,##0}", count );
    

    It only keeps the last line. Depending on your problem, you can also load and process a series of lines.

    0 comments No comments

0 additional answers

Sort by: Most helpful