I work in VB.net only. I cal read an entire file in one statement, sort it with another statement and write it bacl in another. Three statements to sort a csv file! This is aswome, but I wan to know how to sort the file on different columns. Here is my code,

 Dim codes(), Saveline As String
        '
        'Read/Write file data
        '
        codes = File.ReadAllLines(FileName)
        '
        'Save sorted copy
        '
        Saveline = codes(0)
        codes(0) = ""
        Array.Sort(codes)
        codes(0) = Saveline
        '
        File.WriteAllLines(FileName, codes)

What I want to do is use array.sort(codes,2)
where the 2 is column 2 or any other column. Obviously this doesnt work or I wouldn't be here. Is there a way to do this with the Array call?

Thanks!

Recommended Answers

All 3 Replies

I don't know about the array method but you might read it into a ListView then see here for how to do a custom sort on any column.

Another suggestion would be a DataGridView which has the ability to sort the data by any column. With a DataTable as the data source you have the option to save/read the data to/from xml formatted text file.

Thank you for all your answers! They helped.

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.