I have read in some CSV values, line by line, that have the following format:
30: "NY", 41: "JOHN S.", 36: "HAMPTON", 42: "123 Road Street, NY", 68: "Y"
I need to break this down to something like the following in order to parse these items further:
30: "NY"
41: "JOHN S."
36: "HAMPTON"
42: "123 Road Street, NY" (note the comma)
...
I’m using the FileHelper library, but it seems to like reading things in line-by-line, despite me wanting it split by it’s delimited , commas.
I have the record class:
[DelimitedRecord(",")]
class BoxRecord
{
public String record;
}
And I retrieve what I hoped would be several objects in an array via the following, but it just returns me the original line:
DelimitedFileEngine engine = new DelimitedFileEngine(typeof(BoxRecord));
BoxRecord[] boxes = (BoxRecord[])engine.ReadString(boxLine);
What I want boxes[].record to contain:
30: "NY"
41: "JOHN S."
36: "HAMPTON"
42: "123 Road Street, NY"
...
What it actually contains:
30: "NY", 41: "JOHN S.", 36: "HAMPTON", 42: "123 Road Street, NY", 68: "Y"
After getting the line, you can break the line based on below linq to get what you want:
Update: Seem it’s interesting for me, this code is to handle the case as your comment: