Reputation: 10695
I would like to pass a string containing a delimiter, like ","
to an F# function, but the caller is getting an error indicating that because ","
is not a string[]
.
[<EntryPoint>]
let main argv =
let csv_fileH = initCsvLib "test1.csv" ","
The library code below is written to create its own delimiter, but it would be nice to pass the delimiter so pipe and other delimited files could be read.
namespace Toa.csv_lib
.
.
.
(* Contains various necessary open statements *)
[<AutoOpen>]
module csv_lib =
let initCsvLib fn =
let csv_delim = ","
let csv_fileH = new TextFieldParser(fn:string)
csv_fileH.TextFieldType = FieldType.Delimited |> ignore
csv_fileH.SetDelimiters(csv_delim) |> ignore
csv_fileH
What is the best way to convert a string type to string[]? I've been looking on Microsoft's site and other places as well.
Upvotes: 1
Views: 76
Reputation: 26184
If the method SetDelimiters
expects an array of many delimiters (as the name also suggests) you can pass [|","|]
and it should work.
Probably they did that way because one might eventually need to pass multiple delimiters, i.e.
[|","; "|"|]
Upvotes: 6