|
@@ -1,6 +1,8 @@
|
1
|
1
|
import java.io.File;
|
2
|
2
|
import java.io.IOException;
|
3
|
3
|
import java.util.Scanner;
|
|
4
|
+import java.util.regex.Pattern;
|
|
5
|
+import java.util.regex.Matcher;
|
4
|
6
|
|
5
|
7
|
/**
|
6
|
8
|
* Created by thook on 10/7/15.
|
|
@@ -9,6 +11,7 @@ public class HamletParser {
|
9
|
11
|
|
10
|
12
|
private String hamletData;
|
11
|
13
|
|
|
14
|
+
|
12
|
15
|
public HamletParser(){
|
13
|
16
|
this.hamletData = loadFile();
|
14
|
17
|
}
|
|
@@ -36,4 +39,33 @@ public class HamletParser {
|
36
|
39
|
return hamletData;
|
37
|
40
|
}
|
38
|
41
|
|
|
42
|
+ public String replaceHamlet(){
|
|
43
|
+ Pattern hamletPattern = Pattern.compile("(Hamlet)", Pattern.CASE_INSENSITIVE);
|
|
44
|
+ Matcher hamletMatcher = hamletPattern.matcher(hamletData);
|
|
45
|
+ hamletData = hamletMatcher.replaceAll("Leon");
|
|
46
|
+ return hamletData;
|
|
47
|
+
|
|
48
|
+ }
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+ public String replaceHoratio(){
|
|
52
|
+ Pattern horatioPattern = Pattern.compile("(Horatio)", Pattern.CASE_INSENSITIVE);
|
|
53
|
+ Matcher horatioMatcher = horatioPattern.matcher(hamletData);
|
|
54
|
+ hamletData = horatioMatcher.replaceAll("Tariq");
|
|
55
|
+ return hamletData;
|
|
56
|
+
|
|
57
|
+ }
|
|
58
|
+
|
|
59
|
+ public static void main(String[] args) {
|
|
60
|
+ HamletParser hamlet1 = new HamletParser();
|
|
61
|
+ hamlet1.replaceHamlet();
|
|
62
|
+ System.out.print(hamlet1.getHamletData());
|
|
63
|
+ hamlet1.replaceHoratio();
|
|
64
|
+ System.out.print(hamlet1.getHamletData());
|
|
65
|
+ }
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
|
39
|
71
|
}
|