list - How can I parse a csv file and fit it to an existing table in C#? -


okay, right have parsecsv function returns table me in 2d format so:

list<string[]> data = parsecsvfle(file); 

now, i'd rows in 'data' arranged in particular order. order determined first column in temp (i.e. first element of string array). order maintained in string array elsewhere.

string[] dogs = {"rottweiler", "germanshepherd", "dalmatian"}; 

how rearrange 'data' reflect order in 'dogs'?

additional constraints include

  • the string in 'dogs' may substring of string in 'data'. in case, string 'dogs' displayed.
  • the string in 'dogs' may not present in 'data' @ all. in case, string 'dogs' added 2d table blanks in other columns.

example data

data_initial

dalmatian 45 52 rottweiler 58

data_final

rottweiler 58 - germanshepherd - - dalmatian 45 52

thanks looking, all.

if understand correctly want sort content of rows header entry, 1 of dogs - in case custom sort comparer trick.

static string[] dogs = {"rottweiler", "germanshepherd", "dalmatian"};  public static int comparerows(string[] row1, string[] row2) {     int idx1 = array.indexof(dogs,row1[0]);     int idx2 = array.indexof(dogs,row2[0]);      if(idx1 == idx2)         return 0;     else return (idx1 < idx2) ? -1 : 1; }  public static void testarraysort() {     string [] data1 = { "germanshepherd", "rufus", "george"};     string[] data2 = { "dalmatian", "mimi", "dalma" };     string[] data3 = { "rottweiler", "fifi", "dawg" };      list<string[]> data = new list<string[]>() { data1, data2, data3 };     data.sort(comparerows); } 

Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -