2

I have an F# Library I call from C# that reads JSON output and CSV files. The library does processing of the data.

When reading a CSV file to a datatable, I can iterate over the header row like this:

let myfile=FSharp.Data.CsvFile.Load(inFile)
let headers=[| myfile.Headers.Value |]
headers.[0]
            |>Seq.iter(fun y-> dataTable.Columns.Add(new DataColumn(y)))

What I want to do is pass in a pipe-delimited string as a parameter(hdrString) from C# in the event the file does not contain a header. e.g. "Col1|Col2|Col3". I was intending to use match to determine if the string was empty then revert to the file headers by splitting the string. I can't, however, seem to split the string (hdrString.split [ '|' ]) successfully into an string array (string[] []). I've tried split but it gives me an error, essentially, that I can't convert string to obj. I also tried hdrString.ToCharArray() but char[] is not compatible with string[]. Any suggestions on how I can do this?

1
  • 1
    The appropriate method is using String.Split. You should add the errors you got from that. Commented Dec 17, 2014 at 17:36

1 Answer 1

1

In your example you say you tried hdrString.split [ '|' ] where [ '|' ] denotes a list of chars, not an array of chars. Try instead:

let hdrString = "Col1|Col2|Col3"
hdrString.Split [| '|' |]

And probably it's a typo but .split is .Split (with capital S).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.