确定CSV文件中的分隔符. [英] Determining separator character in a CSV file.

查看:423
本文介绍了确定CSV文件中的分隔符.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好

有没有一种方法可以自动确定C#中的分隔符.我不知道该让用户从组合框中选择字符还是由代码确定.任何Helo都会很好.

Is there a way to automaticaly determine the separator character in C#. I don't know if I should make user to choose characte from a combobox or determine by code. Any helo will be good.

推荐答案

我个人不会尝试自动决策. Excel还可以使用许多预定义的分隔符(例如,",;","|"等).

Personally I would never try an automatic decision. Also Excel works with a number of predefined separators (like ",", ";", "|" just to mention a few).

无论如何,如果您要执行自动决定,则危险地"选择(;-))反对解析(当今的演示概念,像编译器原理一样,很少有程序员知道).您应该有一种方法来分析最经常出现的情况 在句子中通常不是正统的"该文件中的字符并进行假设.基于假设,您应该尝试将与假定的分隔符一起生成的文件传递给解析器,并查看生成的表是否与某些正确性"足够匹配. 规则,那么您应该根据所涉及的业务来建立(坐标?命令?菜谱中的食谱?)

If you anyway want to implement an automatic decision you "dangerously" ( ;-) ) walk against parsing (a demodè concept nowadays, like the compiler doctrines few programmer knows). You should have a way to analyze the most recurrent "typically not orthodox in sentences" chars in the file and make assumptions. Based on assumptions you should try to pass to your parser the files generated along with the presumed separator, and see if the resultant tables match enough with some "correctness" rule, that you should establish based on the business you are involved in (coordinates? commands? recipes in the cookbook?)

朱塞佩


这篇关于确定CSV文件中的分隔符.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆