|
@@ -1,6 +1,7 @@
|
1
|
1
|
import java.io.File;
|
2
|
2
|
import java.io.IOException;
|
3
|
3
|
import java.util.Scanner;
|
|
4
|
+import java.util.regex.Pattern;
|
4
|
5
|
|
5
|
6
|
/**
|
6
|
7
|
* Created by thook on 10/7/15.
|
|
@@ -16,7 +17,7 @@ public class HamletParser {
|
16
|
17
|
private String loadFile(){
|
17
|
18
|
ClassLoader classLoader = getClass().getClassLoader();
|
18
|
19
|
File file = new File(classLoader.getResource("hamlet.txt").getFile());
|
19
|
|
- StringBuilder result = new StringBuilder("");
|
|
20
|
+ StringBuilder result = new StringBuilder();
|
20
|
21
|
|
21
|
22
|
try(Scanner scanner = new Scanner(file)){
|
22
|
23
|
while(scanner.hasNextLine()){
|
|
@@ -36,4 +37,13 @@ public class HamletParser {
|
36
|
37
|
return hamletData;
|
37
|
38
|
}
|
38
|
39
|
|
|
40
|
+ public String changeHamletToLeon(String hamlet) {
|
|
41
|
+ hamlet = getHamletData();
|
|
42
|
+ return hamlet.replaceAll( "(?i:.*HAMLET*)", "Leon");
|
|
43
|
+ }
|
|
44
|
+
|
|
45
|
+ public String changeHoratioToTariq(String hamlet) {
|
|
46
|
+ hamlet = getHamletData();
|
|
47
|
+ return hamlet.replaceAll("(?i:.*HORATIO*)", "Tariq");
|
|
48
|
+ }
|
39
|
49
|
}
|