-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRemoveCharacters.java
More file actions
95 lines (84 loc) · 2.07 KB
/
RemoveCharacters.java
File metadata and controls
95 lines (84 loc) · 2.07 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
class CharList {
char ch;
CharList next;
CharList firstNode;
public CharList() {
next = null;
}
public void createList(String str) {
int i;
CharList tmpNode = this;
CharList newNode;
tmpNode.ch = str.charAt(0);
for (i = 1; i < str.length(); i++) {
newNode = new CharList();
newNode.ch = str.charAt(i);
tmpNode.next = newNode;
tmpNode = tmpNode.next;
}
}
public void removeChar(String delStr) {
int i;
CharList tmpNode;
CharList prevNode;
firstNode = this;
for (i = 0; i < delStr.length(); i++) {
tmpNode = firstNode;
prevNode = firstNode;
while (tmpNode != null && tmpNode.ch == delStr.charAt(i)) {
prevNode = tmpNode;
tmpNode = tmpNode.next;
}
firstNode = tmpNode;
if (tmpNode == null) {
continue;
}
while (tmpNode != null) {
if (tmpNode.ch == delStr.charAt(i)) {
prevNode.next = tmpNode.next;
} else {
prevNode = tmpNode;
}
tmpNode = tmpNode.next;
}
}
}
public String getList() {
CharList tmpNode = this;
StringBuffer sb = new StringBuffer();
while (tmpNode != firstNode) {
tmpNode = tmpNode.next;
}
while (tmpNode != null) {
sb.append(tmpNode.ch);
tmpNode = tmpNode.next;
}
return sb.toString();
}
}
public class RemoveCharacters {
public String deleteCharacters(String str, String delChar) {
CharList cl = new CharList();
cl.createList(str);
cl.removeChar(delChar);
return cl.getList();
}
public RemoveCharacters(String filename) throws IOException {
BufferedReader br = new BufferedReader(new FileReader(filename));
String line;
while ((line = br.readLine()) != null) {
String[] params = line.split(",\\s");
System.out.println(deleteCharacters(params[0], params[1]).trim().replaceAll("( )+", " "));
}
}
public static void main(String[] args) throws IOException {
if (args.length != 1) {
System.out.println("Unsupported number of parameters passed. Exiting.");
System.exit(1);
}
RemoveCharacters rc = new RemoveCharacters(args[0]);
}
}