hi everyone,

I am reletively new to c sharp and have a question regarding a console application I have created. I have a text file which contain 16 records which i want to sort in dob order. I was wandering how i could split the data so when i run the application i will be able to scale through the dates in order of date of birth, the first line of the text file looks like this

Dean,James,1952/09/01,M


I have read the file using streamreader but I am stuck on where to go from here. Any help will be greatly appreciated

Many thanks

Recommended Answers

All 8 Replies

Please could you post what you have so far please? Show us something we can work on, without having to guess what you're using!

Also, have a look into the LINQ library which could sort the DOB easier.

Hope this helps =)

using System;
using System.Collections;
using System.Linq;
using System.Text;
using System.IO;

namespace ConsoleApplication5
{
    class Program
    {
        static void Main(string[] args)
        {
            StreamReader myFile = new System.IO.StreamReader(@"C:\Documents and Settings\Alane\My Documents.txt");
            string str1 = myFile.ReadToEnd().ToString();
            string[] str = str1.Split(new char[] { ',' });
            myFile.Close();
            string name = str[0];
            string name2 = str[1];
            string date = str[2];
            string date2 = str[3];
        }
    }
}

I Have 15 records on the text file so would i possibly need 15 arrays? many thanks

Hey, can you post what you have in your "My Documents.txt" file and, for future reference put your code in tags (Y)

Also, you wouldn't need 15 arrays, only one array that stores the values.. That's the point of an array! :)

Black,Jack,1968/04/01,M
Bloggs,Joe,1995/05/28,M
Navarro,steve,Colin,1948/11/5,M
Robertson,Kerry,1990/4/07,F
Perry,Katy,1984/4/16,F
Mcardle,Elaine,1990/10/08,F
Gerrard,Steven,1980/12/12,M
Suarez,Luis,1988/2/04,M
Monroe,Marylyn,1952/09/01,F
Carragher,Jamie,1978/08/15,M
Barnes,John,1969/07/18,M
Jones,Lisa,1989/02/18,F
Connary,Sean,1944/09/01,M
Brosnan,Pierce,1970/04/30,M
Clarke,Lois,1992/02/02,F

Thanks

If you read the data into a class and put that class in a list, you can easily sort by a particular field.
Do you have any restrictions on the types of technology you can use?

I was looking to keep the code as simple as possible as I am a newbie, I was looking to use basic structures and arrays. I want the program to have a key to scroll to the next record and back, Many thanks

If you are willing to split (and re-order) the data as you read it (putting the date part first), you can put it in a List<string> and then just call .Sort();
... but I just noticed one row has a 3-part name. Was that intentional?

many thanks for your help

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.