How to programmatically guess whether a CSV file is comma or semicolon delimited

前端 未结 5 1816
滥情空心
滥情空心 2021-01-04 08:29

In most cases, CSV files are text files with records delimited by commas. However, sometimes these files will come semicolon delimited. (Excel will use semicolon delimiter

5条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-04 09:06

    Depending on what you are working with, if you will guaranteeing have a header row, your approach of trying both, could be the best overall practice. Then once you determine what is going on, if you get to a row further down that doesn't have the required number of columns then you know that the format isn't correct.

    Typically i would see this as a user specified option on upload, rather than a programmatic test.

提交回复
热议问题