Reputation: 3581
I'm trying to write the following C# code to F#:
List<string> addresses = File.ReadLines(CsvPath).Select(x => x.Split(';')[0]).Distinct().ToList();
addresses.ForEach(a => Console.WriteLine(a));
This is what I've come up with:
let addresses = File.ReadLines(CsvPath) |> Seq.iter (fun s1 ->
s1.Split [|';'|].[0]
|> Console.WriteLine
)
However this outputs System.String[] instead of the first string value of the line...
Upvotes: 0
Views: 70
Reputation: 6629
You need to put the argument of s1.Split
in parentheses, so you actually index on the result, not the argument.
let addresses =
File.ReadLines(CsvPath)
|> Seq.iter (fun s1 ->
s1.Split([|';'|]).[0]
|> Console.WriteLine)
Upvotes: 1