简体   繁体   English

从文本文件读取; 如何确定每行包含几个字段?

[英]Reading from a text file; how do I determine how many fields each line holds?

So, I'm trying to read from a text file and store each line into an object, and then each individual value (split by ',') into a list. 因此,我正在尝试从文本文件读取并将每一行存储到一个对象中,然后将每个单独的值(由','分隔)存储到一个列表中。 Here's a quick example: 这是一个简单的示例:

Text file dummy information: 文本文件虚拟信息:
1, Book One, 22, 5 1,一书22、5
2, Book Two, 10, 3 2,第二,十,三本书
3, Book Three, 5, 15 3,第三本书,5,15

But if for example, line 2 had the following: 但是,例如,如果第2行具有以下内容:

Text file dummy information: 文本文件虚拟信息:
1, Book One, 22, 5 1,一书22、5
2, Book Two, 10, 3, 22.0, 5 2,第二本书,10,3,22.0,5
3, Book Three, 5, 15 3,第三本书,5,15

If I understand correctly, It seems that checking the length of the current holdingArray should tell you which line has more -or less- values than expected. 如果我理解正确,似乎检查当前 holdingArray的长度应该可以告诉您哪一行的值比预期的多或少。 After all, you are splitting the lines by the comma character. 毕竟,您要用逗号分隔行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM