Michal_5 0 Newbie Poster

Hi All.
I have a problem with col sorting of my csv file

 public static void SORT(string input, int col_num)
        {
            string[] lines = input.Split(new[] { Environment.NewLine }, StringSplitOptions.None);
            var data = lines.Skip(1);
            var sorted = data.Select(line => new
            {
                SortKey = Int32.Parse(line.Split(';')[16]),
                Line = line
            }
            ).OrderBy(x => x.SortKey).Select(x => x.Line).ToList();

            Console.WriteLine(output);
            File.WriteAllLines("D:\\sortedCsv.csv", lines.Take(1).Concat(sorted), Encoding.Default);

        }

What I receive is an error: input string in incorrect format and I dont know how to fix it.

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.