Last active
September 10, 2022 18:43
-
-
Save peheje/01771f6e0f7dbf8a1e231269283fd870 to your computer and use it in GitHub Desktop.
Simple CSV reader F#
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| open Microsoft.VisualBasic.FileIO | |
| open System.IO | |
| let parseRow (row: string array) = | |
| // Implement this yourself | |
| let name = row[0] | |
| let username = row[2] | |
| let password = row[3] | |
| $"{name},{username},{password}" | |
| let read (path: string) = | |
| let rec loop (parser: TextFieldParser) output = | |
| match parser.EndOfData with | |
| | false -> loop parser ((parser.ReadFields()) :: output) | |
| | true -> output |> List.rev |> List.map parseRow | |
| let parser = new TextFieldParser(path, Delimiters = [|","|], HasFieldsEnclosedInQuotes = true) | |
| loop parser [] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment