This project is read-only.
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:
let ReadCSVFile1() = 

// Write a test file
System.IO.File.WriteAllLines(@"test.csv", [| "Desmond, Barrow, Market Place, 2";
"Molly, Singer, Band, 12" |]);
// Now read it
let linesSplitIntoWords =
System.IO.File.ReadAllLines(@"test.csv")
|> Array.map (fun line -> line.Split [|',';' ';'\t'|])
printfn "%A" linesSplitIntoWords
Execution Result:
[|[|"Desmond"; ""; "Barrow"; ""; "Market"; "Place"; ""; "2"|];
[|"Molly"; ""; "Singer"; ""; "Band"; ""; "12"|]|]

Last edited Sep 14, 2011 at 3:42 AM by ttliu2000, version 1

Comments

No comments yet.