Autodetect Presence of CSV Headers in a File

后端 未结 6 1536
心在旅途
心在旅途 2020-12-25 13:23

Short question: How do I automatically detect whether a CSV file has headers in the first row?

Details: I\'ve written a small CSV parsing engine th

6条回答
  •  甜味超标
    2020-12-25 13:29

    In the most general sense, this is impossible. This is a valid csv file:
    Name
    Jim
    Tom
    Bill

    Most csv readers will just take hasHeader as an option, and allow you to pass in your own header if you want. Even in the case you think you can detect, that being character headers and numeric data, you can run into a catastrophic failure. What if your column is a list of BMW series?
    M
    3
    5
    7

    You will process this incorrectly. Worst of all, you will lose the best car!

提交回复
热议问题