Skip to content

Instantly share code, notes, and snippets.

@peheje
Last active September 10, 2022 18:43
Show Gist options
  • Select an option

  • Save peheje/01771f6e0f7dbf8a1e231269283fd870 to your computer and use it in GitHub Desktop.

Select an option

Save peheje/01771f6e0f7dbf8a1e231269283fd870 to your computer and use it in GitHub Desktop.

Revisions

  1. peheje revised this gist Sep 10, 2022. 1 changed file with 3 additions and 13 deletions.
    16 changes: 3 additions & 13 deletions csvReader.fs
    Original file line number Diff line number Diff line change
    @@ -1,19 +1,9 @@
    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

    if parser.EndOfData then output |> List.rev
    else loop parser ((parser.ReadFields()) :: output)

    let parser = new TextFieldParser(path, Delimiters = [|","|], HasFieldsEnclosedInQuotes = true)
    loop parser []
  2. peheje created this gist Sep 10, 2022.
    19 changes: 19 additions & 0 deletions csvReader.fs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    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 []