如何从文本文件中的每一行拆分单个列值? [英] How can I split out individual column values from each line in a text file?
本文介绍了如何从文本文件中的每一行拆分单个列值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要解析ASCII文本文件中的行。
列由可变数量的空格分隔,例如:
I have lines in an ASCII text file that I need to parse. The columns are separated by a variable number of spaces, for instance:
column1 column2 column3
我如何拆分此行以返回仅包含值的数组?
How would i split this line to return an array of only the values?
谢谢
推荐答案
String testvar = "Some Data separated by whitespace";
String[] vals = testvar.split("\\s+");
\s
表示空格字符, +
表示1或更多。 .split()
将字符串拆分为除以指定分隔符的部分(在本例中为1个或多个空格字符)。
\s
means a whitespace character, the +
means 1 or more. .split()
splits a string into parts divided by the specified delimiter (in this case 1 or more whitespace characters).
这篇关于如何从文本文件中的每一行拆分单个列值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文