我有一个txt文件,其中某些列并未出现在每一行中,但这会导致问题,在它们出现的行中,它们弄乱了我的列的顺序:
35 = d | 5799 = 00000000 | 980 = A | 779 = 20190721173046000465 | 1180 = 310 | 1300 = 64 | 462 = 5 | 207 = XCME | 1151 = ES | 6937 = ES | 55 = ESM0 | 48 = 163235 | 22 = 8 | 167 = FUT | 461 = FFIXSX | 200 = 202006 | 15 = USD | 1142 = F | 562 = 1 | 1140 = 3000 | 969 = 25.000000000 | 9787 = 0.010000000 | 996 = IPNT | 1147 = 50.000000000 | 1150 = 302775.000000000 | 731 = 00000110 | 5796 = 20190724 | 1149 = 315600.000000000 | 1148 = 285500.000000000 | 1143 = 600.000000000 | 1146 = 12.500000000 | 9779 = N | 864 = 2 | 865 = 5 | 1145 = 20190315133000000000 | 865 = 7 | 1145 = 20200619133000000000 | 1141 = 1 | 1022 = GBX | 264 = 10 | 870 = 1 | 871 = 24 | 872 = 00000000000001000010000000001111 | 1234 = 0 | 5791 = 279 | 5792 = 10121 |
35 = d | 5799 = 00000000 | 980 = A | 779 = 20190721173046000465 | 1180 = 310 | 1300 = 64 | 462 = 5 | 207 = XCME | 1151 = ES | 6937 = ES | 55 = ESU9 | 48 = 191262 | 22 = 8 | 167 = FUT | 461 = FFIXSX | 200 = 201909 | 15 = USD | 1142 = F | 562 = 1 | 1140 = 3000 | 969 = 25.000000000 | 9787 = 0.010000000 | 996 = IPNT | 1147 = 50.000000000 | 1150 = 302150.000000000 | 731 = 00000110 | 5796 = 20190724 | 1149 = 315700.000000000 | 1148 = 285600.000000000 | 1143 = 600.000000000 | 1146 = 12.500000000 | 9779 = N | 864 = 2 | 865 = 5 | 1145 = 20180615133000000000 | 865 = 7 | 1145 = 20190920133000000000 | 1141 = 1 | 1022 = GBX | 264 = 10 | 870 = 1 | 871 = 24 | 872 = 00000000000001000010000000001111 | 1234 = 0 | 5791 = 250519 | 5792 = 452402 |
35 = d | 5799 = 00000000 | 980 = A | 779 = 20190721173046000465 | 1180 = 310 | 1300 = 64 | 462 = 5 | 207 = XCME | 1151 = $ E | 6937 = 0ES | 55 = 0ESQ9 | 48 = 229588 | 22 = 8 | 167 = FUT | 461 = FFIXSX | 200 = 201908 | 15 = USD | 1142 = F | 562 = 1 | 1140 = 3000 | 969 = 25.000000000 | 9787 = 0.010000000 | 996 = IPNT | 1147 = 50.000000000 | 1150 = 25.000000000 | 731 = 00000011 | 5796 = 20190607 | 1143 = 0.000000000 | 1146 = 12.500000000 | 9779 = N | 864 = 2 | 865 = 5 | 1145 = 20190621133000000000 | 865 = 7 | 1145 = 20190816133000000000 | 1141 = 1 | 1022 = GBX | 264 = 10 | 870 = 1 | 871 = 24 | 872 = 00000000000001000010000000001111 | 1234 = 0 |
35 = d | 5799 = 00000000 | 980 = A | 779 = 20190721173114000729 | 1180 = 441 | 1300 = 56 | 462 = 16 | 207 = DUMX | 1151 = 1O | 6937 = OQE | 55 = OQEH4 C6100 | 48 = 1546 | 22 = 8 | 167 = OOF | 461 = OCEFPS | 201 = 1 | 200 = 202403 | 15 = USD | 202 = 6100.000000000 | 947 = USD | 9850 = 0.100000000 | 1142 = F | 562 = 1 | 1140 = 999 | 969 = 1.000000000 | 1146 = 10.000000000 | 9787 = 0.010000000 | 996 = BBL | 1147 = 1000.000000000 | 731 = 00000001 | 1148 = 0.100000000 | 9779 = N | 5796 = 20190718 | 864 = 2 | 865 = 5 | 1145 = 20181031213000000000 | 865 = 7 | 1145 = 20240126193000000000 | 1141 = 1 | 1022 = GBX | 264 = 3 | 870 = 1 | 871 = 24 | 872 = 00000000000001000000000100000000101 | 1234 = 1 | 1093 = 4 | 1231 = 1.0000 | 711 = 1 | 309 = 211120 | 305 = 8 | 311 = OQDH4 | 1647 = 0 |
35 = d | 5799 = 00000000 | 980 = A | 779 = 20190721173115000229 | 1180 = 441 | 1300 = 56 | 462 = 16 | 207 = DUMX | 1151 = 1O | 6937 = OQE | 55 = OQEM4 C5700 | 48 = 2053 | 22 = 8 | 167 = OOF | 461 = OCEFPS | 201 = 1 | 200 = 202406 | 15 = USD | 202 = 5700.000000000 | 947 = USD | 9850 = 0.100000000 | 1142 = F | 562 = 1 | 1140 = 999 | 969 = 1.000000000 | 1146 = 10.000000000 | 9787 = 0.010000000 | 996 = BBL | 1147 = 1000.000000000 | 731 = 00000001 | 1148 = 0.100000000 | 9779 = N | 5796 = 20190718 | 864 = 2 | 865 = 5 | 1145 = 20181031213000000000 | 865 = 7 | 1145 = 20240425183000000000 | 1141 = 1 | 1022 = GBX | 264 = 3 | 870 = 1 | 871 = 24 | 872 = 00000000000001000000000100000000101 | 1234 = 1 | 1093 = 4 | 1231 = 1.0000 | 711 = 1 | 309 = 329748 | 305 = 8 | 311 = OQDM4 | 1647 = 0 |
例如,在前三行中总是出现461=…
,然后是200=…
,而从461=…
和200=…
之间的第四行开始则是201=…
现在,我想到了以某种方式将稍后出现的每一列(第一行中没有的那一列)移动到该行的末尾,从而使其成为最后一列,但是我不知道该怎么做。这是我尝试过的:
private static void ladeDatei(String datName) {
File file = new File(datName);
if (!file.canRead() || !file.isFile())
System.exit(0);
BufferedReader in = null;
try {
in = new BufferedReader(new FileReader(datName));
String row = null;
String row2 = null;
while ((row = in.readLine()) != null) {
System.out.println("Gelesene Zeile: " + row);
while(row.contains("|")) {
row2 = row.substring(row.indexOf("|") + 1);
row=row2;
row2 = row.substring(0, row.indexOf("=") + 1);
row2 = row2.replace("=", "");
if(!numbers.contains(row2)) {
numbers.add(row2);
}
System.out.println(row);
//System.out.println(row2);
}
}
} catch (IOException e) {
e.printStackTrace();
} finally {
if (in != null)
try {
in.close();
} catch (IOException e) {
}
}
}
我想过将|并将它们保存在textArr列表中,但是我不知道哪些行属于同一行。我的主要问题是,我不知道一种检查该列是否存在于较早行中以及如何将其移至该行末尾的好方法。
编辑:现在我将每个新条目保存在数字arraylist中(请参见上面的代码,在我的编辑中),但是现在我被卡住了,因为我不知道如何将它们及其后的所有元素移动到每一行的末尾。
最佳答案
那真是一件难事。我要做的是:
(1)在|
处分割行
(2)创建一个List
,在其中将数字附加在|
和=
之间(在每个新数字后面附加)
(3)制作Map
,其中线部分映射为(2)中的数字作为键
(4)生成第二个Map
,其中线部分的最大列值映射到(2)中的数字
(5)从(2)joinig关联的行部分中通读List,并用|
填充到max-column-values
(如果没有用于特定编号的线部分,则也必须进行填充)
只要有可能,我都希望在html表中构造线条部分。
列顺序的更改不会解决更大或更小的列的问题。