Beispiel #1
0
        /// <summary>
        /// Read data from SWAT output file using TextFieldParser
        /// </summary>
        /// <remarks>
        /// 1. Need to know the number and width of columns
        /// 2. Doesn't support select partial data
        /// </remarks>
        static void TestExtractFromText_TextFieldParser(string filePah)
        {
            Console.WriteLine("TextFieldParser");
            DateTime before = DateTime.Now;

            using (Microsoft.VisualBasic.FileIO.TextFieldParser reader =
                       new Microsoft.VisualBasic.FileIO.TextFieldParser(filePah))
            {
                reader.TextFieldType = Microsoft.VisualBasic.FileIO.FieldType.FixedWidth;
                reader.SetFieldWidths(6, 4, 10, 4,
                                      10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
                                      10, 10, 10, 10, 10, 10, 10, 10, 10, 11,
                                      10, 10, 10, 6);
                string[] currentRow = null;
                int      i          = 0;
                //ignore the first 9 lines
                while (!reader.EndOfData && i < 9)
                {
                    reader.ReadLine();
                    i++;
                }
                while (!reader.EndOfData)
                {
                    currentRow = reader.ReadFields();
                }
            }
            DateTime after = DateTime.Now;

            Console.WriteLine(string.Format("******\nTime Used: {0} seconds\n******", after.Subtract(before).TotalSeconds));
        }
Beispiel #2
0
 /// <summary>
 /// Read data from SWAT output file using TextFieldParser
 /// </summary>
 /// <remarks>
 /// 1. Need to know the number and width of columns
 /// 2. Doesn't support select partial data
 /// </remarks>
 static void TestExtractFromText_TextFieldParser(string filePah)
 {
     Console.WriteLine("TextFieldParser");
     DateTime before = DateTime.Now;
     using (Microsoft.VisualBasic.FileIO.TextFieldParser reader =
         new Microsoft.VisualBasic.FileIO.TextFieldParser(filePah))
     {
         reader.TextFieldType = Microsoft.VisualBasic.FileIO.FieldType.FixedWidth;
         reader.SetFieldWidths(6,4,10,4,
             10,10,10,10,10,10,10,10,10,10,
             10,10,10,10,10,10,10,10,10,11,
             10,10,10,6);
         string[] currentRow = null;
         int i = 0;
         //ignore the first 9 lines
         while (!reader.EndOfData && i<9)
         {
             reader.ReadLine();
             i++;
         }
         while(!reader.EndOfData)
            {
                currentRow = reader.ReadFields();
            }
     }
     DateTime after = DateTime.Now;
     Console.WriteLine(string.Format("******\nTime Used: {0} seconds\n******", after.Subtract(before).TotalSeconds));
 }