Read Entire CSV File, .NET style - vilinski/nemerle GitHub Wiki

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

[Copyright ©](Terms of use, legal notice)