[c09aa8]: / clusters / scripts / cleaninds.java

Download this file

48 lines (47 with data), 1.3 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import java.util.*;
import java.io.*;
public class cleaninds {
public static void main(String[] args) throws Exception {
Scanner in = new Scanner(new File("ctrpinds.csv"));
PrintWriter out = new PrintWriter(new File("cleanctrpinds.csv"));
while (in.hasNext()) {
String line = in.nextLine();
int count = 0;
String id = "";
String link = "";
String cur = "";
boolean breaker = false;
int i = 0;
for ( ; i < line.length(); i++) {
if (line.charAt(i) == ',') {
if (id.equals("")) id = cur;
else {
link = cur;
breaker = true;
}
cur = "";
}
else cur = cur + line.charAt(i);
if (breaker) break;
}
int dex = i;
int trudex = line.indexOf(",true", dex);
int faldex = line.indexOf(",false", dex);
while (trudex != -1 || faldex != -1) {
dex = faldex;
int toAdd = 1;
if (faldex == -1 || trudex < faldex && trudex != -1) {
dex = trudex;
toAdd = 0;
}
System.out.println(trudex + " " + faldex + " " + i + " " + dex + " " + line);
out.println(id + "," + link + "," + line.substring(i+1, dex + 5 + toAdd));
i = dex + 5 + toAdd;
trudex = line.indexOf(",true", i);
faldex = line.indexOf(",false", i);
}
}
in.close();
out.close();
}
}