I have a text file which contains following
Name address phone        salary
Jack Boston  923-433-666  10000
all the fields are delimited by the spaces.
I am trying to write a C# program, this program should read a this text file and then store it in the formatted array.
My Array is as follows:
address
salary
When ever I am trying to look in google I get is how to read and write a text file in C#.
Thank you very much for your time.
You can use File.ReadAllLines method to load the file into an array. You can then use a for loop to loop through the lines, and the string type's Split method to separate each line into another array, and store the values in your formatted array.
Something like:
    static void Main(string[] args)
    {
        var lines = File.ReadAllLines("filename.txt");
        for (int i = 0; i < lines.Length; i++)
        {
            var fields = lines[i].Split(' ');
        }
    }
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With