0

When I read in this file it reads in the entire line.

string filename ="f:\\date.txt";
            
            FileStream f = new FileStream(filename, FileMode.Open);
            StreamReader stream = new StreamReader(f);
            
            int line;
          

            int[] array = new int[15]; 
            for (int i = 0; i < 15; i++)
            {
               
                line = stream.Read();    // header line
                Console.WriteLine(line);
              
            }

The line it reads in from the file is 001 10:00 ON
How would I read the line if so 001 is as int, 10:00 is a string, and ON is a string?

2
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by aaronmk2
Featured Replies
  • Maybe this will do? : [CODE] string filename = "f:\\date.txt"; using (StreamReader stream = new StreamReader(filename)) { string line; while ((line = stream.ReadLine()) != null) { string[] array = line.Split(' '); int a = Convert.ToInt32(array[0]); //1. string b = array[1]; //2. string c = array[2]; //3. } } [/CODE] Read More

1

Maybe this will do? :

string filename = "f:\\date.txt";
            using (StreamReader stream = new StreamReader(filename))
            { 
                string line;
                while ((line = stream.ReadLine()) != null)
                {
                    string[] array = line.Split(' ');
                    int a = Convert.ToInt32(array[0]); //1.
                    string b = array[1];               //2.
                    string c = array[2];               //3.
                }
            }

Edited by Mitja Bonca: n/a

0

Maybe this will do? :

string filename = "f:\\date.txt";
            using (StreamReader stream = new StreamReader(filename))
            { 
                string line;
                while ((line = stream.ReadLine()) != null)
                {
                    string[] array = line.Split(' ');
                    int a = Convert.ToInt32(array[0]); //1.
                    string b = array[1];               //2.
                    string c = array[2];               //3.
                }
            }

Thanks I never thought about splitting the string.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.