ล็อกแล้ว Setting Row Headers In A CSV

  • 13 มีนาคม 2555 10:54
     
     


    • แก้ไขโดย matta0990 13 มีนาคม 2555 15:46 error
    •  

ตอบทั้งหมด

  • 13 มีนาคม 2555 12:38
     
     คำตอบ มีโค้ด

    No error checking here to ensure that each row actually contains the columns, but you get the idea:

       List<string[]> parsedData = new List<string[]>();
    
       using (StreamReader readfile = new StreamReader(path))
       {
        string line;
        string[] row;
    
        while ((line = readfile.ReadLine()) != null)
        {
         row = line.Split(',');
         parsedData.Add(new string[]{row[5], row[8]});
        }
       }

    Additionally, I would look for a better storage mechanism than a List of strings, perhaps a List of classes that would better describe the data.

    It would be greatly appreciated if you would mark any helpful entries as helpful and if the entry answers your question, please mark it with the Answer link.


    • แก้ไขโดย TSoftware 13 มีนาคม 2555 12:39 Left off closing }
    • เสนอเป็นคำตอบโดย TSoftware 15 มีนาคม 2555 14:17
    • ทำเครื่องหมายเป็นคำตอบโดย Bob ShenMicrosoft, Moderator 26 มีนาคม 2555 2:42
    •  
  • 13 มีนาคม 2555 15:41
     
     

    hi,

    I have a CSV and need to be able to brake down each row and column so that I can select indervidual cells within the CSV and set them as an object (i think). I would like to select the "Date" from the CSV which may be in "C3" and a value which may be in "C7" and nothing else.

    Is this possible? 

  • 13 มีนาคม 2555 15:55
     
     

    You may want to take a look at this post:

    http://social.msdn.microsoft.com/Forums/en-US/csharplanguage/thread/12c8f825-966c-4900-b1e6-d1bc520e5520

    Since it is almost identical to what you had posted there.


    It would be greatly appreciated if you would mark any helpful entries as helpful and if the entry answers your question, please mark it with the Answer link.