按列而非按行读取文本
【问题】
Java Read Text Column function similar to ReadLine()
I have a text file containing vector information by pin. It looks like this:
PHP Code:
xxxxxxxxxxxxxxxxxxxx pppppppppppppppppppp iiiiiiiiiiiiiiiiiiii nnnnnnnnnnnnnnnnnnnn 12345689111111111122 012345678901 CountPatAdr (Main)(Main) 101000000000000010XXXX 201000000000000010XXXX 301000000000000010XXXX 401000000000000010XXXX 501000000000000010XXXX 601000000000000010XXXX 701000000000000010XXXX 801000000000000010XXXX 901000000000000010XXXX 1001000000000000010XXXX 1101000000000000010XXXX 1201000000000000010XXXX 1301000000000000010XXXX 1401000000000000010XXXX 1501000000000000010XXXX 1601000000000000010XXXX ...
I want to extract the information column by column. So I would like to be able to write or store each pin by line such as: xpin1 11111... xpin2 10000... xpin3 10000... Basically, what I am looking for is exactly the Java readLine() function described here: but instead of reading a text file line-by-line. I want to read column by column. Anyone know of such a function or way to do this?
【回答】
要实现这个算法,需要进行集合成员的拼接和转换。java做这种集合式的运算不难,但代码繁琐比较麻烦;使用 R 或 python 都比较容易,但没法被 java 主程序集成。用 SPL 也容易完成,并且可以被 java 主程序调用 (参考),代码如下:
A1:读取source.txt文件内容,将每一行返回成字符串。
A2:取序列第2-6行数据组成新序列。
A3:取14行之后的数据组成新序列。
A4:正则匹配出需要的数据。
A5:将A4拆分成二维表。
A6:正则匹配出需要的数据。
A7:将A6拆分成二维表。
A8:合并2个二维表。
A9:将每列合并成字符串。