如何将文本文件读取到数组 [英] How do I read text files to arrays
本文介绍了如何将文本文件读取到数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下信息:
I have the following information:
John J Johnson 100 90 79 100 65 81
Ben A Franklin 100 100 100 78 88 98
Patricia T McMillan 60 90 75 83 91 79
Arthur D Dent 78 88 98 75 100 78
Ford M Prefect 99 99 99 100 100 100
如何将每列读取到不同的1维数组?一个2d数组将是一个很好的解决方案,但我被要求读取不同的1维数组。请任何人???
How ca I read every column to a different 1 dimensional array??? A 2d array would be a good solution, but I was ask to read to differents 1 dimensional array. Please anyone???
推荐答案
您可以使用File.ReadAllLines()
读取行,它将为您提供字符串数组(行)。
您可以用line.Split('')
拆分该行line
是上面几行中的一行,你在空格上分割,这将为你提供一系列的单词。
你应该可以从那里做你想做的事。
对于c ++,请阅读以下内容: http://www.cplusplus.com/forum/beginner/ 74757 / [ ^ ]
用于拆分: http://stackoverflow.com/questions/5888022/分割字符串由单空间 [ ^ ]
You can read lines withFile.ReadAllLines()
which will give you an array of strings (lines).
You can split the line withline.Split(' ')
whereline
is a line from the above array of lines and you are splitting on spaces, which will give you a array of words fro the lines.
You should be able to do what you want from there.
For c++ see this for reading lines : http://www.cplusplus.com/forum/beginner/74757/[^]
and this for splitting : http://stackoverflow.com/questions/5888022/split-string-by-single-spaces[^]
这篇关于如何将文本文件读取到数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文