1

I am having an issue with importing a CSV file. The problem arises when an address field has multiple comma seperated values e.g. home no, street no, town etc.

I tried to use http://forums.asp.net/t/1705264.aspx/1 this article but, the problem did not solved because of a single field containing multiple comma separated values.

Any idea or solution? because I didnt found any help

Thanks

2
  • If your using that solution then I'd recommend looking at how you can change what splits the lines up and hope that theres a difference between the address and the separator character Commented May 2, 2013 at 17:51
  • This is a common ETL issue, can the provider either change the delimiter or wrap the strings in double quotes? Commented May 2, 2013 at 17:55

3 Answers 3

2

Don't split the string yourself. Parsing CSV files is not trivial, and using str.Split(',') will give you a lot of headaches. Try using a more robust library like CsvHelper - https://github.com/JoshClose/CsvHelper

If that doesn't work then the format of the file is probably incorrect. Check to make sure the text fields are properly quoted.

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

Comments

0

Do you control the format of the CSV file? You could see about changing it to qualify the values by surrounding them with double quotes (""). Another option is to switch to a different delimiter like tabs.

Barring that, if the address is always in the same format, you could read in the file, and then inspect each record and manually concatenate columns 2, 3, and 4.

2 Comments

What about the second option? Just treat those extra commas like they are valid column delimiters and piece things together at another stage.
csvhelper is perfect for me. I have not made csv files if i created it i could try second option
0

Are the fields surrounded by quotation marks? If so, split on "," rather than just ,.

Is the address field at the beginning or end of a record? If so, you can ignore the first x commas (if at the beginning) or split only the correct number of fields (if at the end).

Ideally, if you have control of the source file's creation, you would change the delimiter of either the address sub-fields, or the record fields.

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.