How about some Linq voodoo ?
Assumptions:
1. BankID is always a unique number
2. the desired result order is by BankID numeric ascending order
private List<string> ProcessCSV(string csv)
{
csv = csv.Replace(" ", String.Empty);
IEnumerable<string> lines = csv.Split(new string[] {Environment.NewLine},StringSplitOptions.RemoveEmptyEntries);
return lines.Skip(1).ToDictionary
(
itm => itm.Substring(0, itm.IndexOf(','))
)
.OrderBy(kvp => Convert.ToInt32(kvp.Key))
.Select(kvp => kvp.Value).ToList();
}
private string csvTrial = @"BankID , DDA, DepositDate, TotalAmount, TotalChecks
224152, 5800956996, 11/04/2013, $15,969.32, 10
4522424, 5800956996, 11/04/2013, $26,303.26, 21
415224, 5800956996, 11/04/2013, $4.12, 0
985758, 5800956996, 11/04/2013, $91,172.66, 8
11124, 5800956996, 11/04/2013, $37,395.50, 7";
Test:
List<string> accounts = ProcessCSV(csvTrial);
Result:
11124,5800956996,11/04/2013,$37,395.50,7
224152,5800956996,11/04/2013,$15,969.32,10
415224,5800956996,11/04/2013,$4.12,0
985758,5800956996,11/04/2013,$91,172.66,8
4522424,5800956996,11/04/2013,$26,303.26,21