Skip to content

Read Entire CSV File, .NET style

CodingUnit edited this page Dec 7, 2011 · 5 revisions

Read Entire CSV File, .NET-style

  • Category: Input/Output
  • Description: Read an entire text file as a string using .NET I/O utilities and abstractions.
  • Code:
using System;
using System.Console;
using System.IO.File;
using Nemerle;
using Nemerle.Collections;

    // Write a test file
    WriteAllLines("test.csv", array["Desmond, Barrow, Market Place, 2", "Molly, Singer, Band, 12" ]);
    // Now read it 
    def text = ReadAllLines("test.csv");
    def linesSplitIntoWords = text.Map(x => x.Split(array[','], StringSplitOptions.RemoveEmptyEntries));
    foreach (l in linesSplitIntoWords) 
      WriteLine($<#..$(l; ", "; w => $"$w")#>);
  • Execution Result:
Desmond,  Barrow,  Market Place,  2
Molly,  Singer,  Band,  12
Clone this wiki locally