按列而非按行读取文本

【问题】

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 
                                     
                                    
                                    
                                    
Count  PatAdr                       
(Main) (Main)                       
     1      0  1000000000000010XXXX 
     2      0  1000000000000010XXXX 
     3      0  1000000000000010XXXX 
     4      0  1000000000000010XXXX 
     5      0  1000000000000010XXXX 
     6      0  1000000000000010XXXX 
     7      0  1000000000000010XXXX 
     8      0  1000000000000010XXXX 
     9      0  1000000000000010XXXX 
    10      0  1000000000000010XXXX 
    11      0  1000000000000010XXXX 
    12      0  1000000000000010XXXX 
    13      0  1000000000000010XXXX 
    14      0  1000000000000010XXXX 
    15      0  1000000000000010XXXX 
    16      0  1000000000000010XXXX 
    ...  

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:
http://java.sun.com/javase/6/docs/ap...redReader.html
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 主程序调用 (参考Java 如何调用 SPL 脚本),代码如下:


A

1

=file("source.txt").read@n()

2

=A1.to(2,6)

3

=A1.to(14,)

4

=A2.regex("(.*) (.*)";a,b).(b)

5

=A4.new(mid(~,1,1),mid(~,2,1),mid(~,3,1),mid(~,4,1),mid(~,5,1),mid(~,6,1),mid(~,7,1),mid(~,8,1),mid(~,9,1),mid(~,10,1),mid(~,11,1),mid(~,12,1),mid(~,13,1),mid(~,14,1),mid(~,15,1),mid(~,16,1),mid(~,17,1),mid(~,18,1),mid(~,19,1),mid(~,20,1))

6

=A3.regex("(.*) (.*)";a,b).(b)

7

=A6.new(mid(~,1,1),mid(~,2,1),mid(~,3,1),mid(~,4,1),mid(~,5,1),mid(~,6,1),mid(~,7,1),mid(~,8,1),mid(~,9,1),mid(~,10,1),mid(~,11,1),mid(~,12,1),mid(~,13,1),mid(~,14,1),mid(~,15,1),mid(~,16,1),mid(~,17,1),mid(~,18,1),mid(~,19,1),mid(~,20,1))

8

=A5|A7

9

=A8.fno().(A8.field(~).concat())

 

A1:读取source.txt文件内容,将每一行返回成字符串

undefined

A2取序列第2-6行数据组成新序列

undefined

A314行之后的数据组成新序列

undefined

A4正则匹配出需要的数据

undefined

A5:将A4拆分成二维表。

undefined

A6正则匹配出需要的数据

undefined

A7:将A6拆分成二维表。

undefined

A8:合并2个二维表。

undefined

A9:将每列合并成字符串。

undefined