|
@@ -1,10 +1,24 @@
|
1
|
1
|
import java.io.File;
|
2
|
2
|
import java.io.IOException;
|
3
|
3
|
import java.util.Scanner;
|
|
4
|
+import java.util.regex.Matcher;
|
|
5
|
+import java.util.regex.Pattern;
|
4
|
6
|
|
5
|
7
|
/**
|
6
|
|
- * Created by thook on 10/7/15.
|
|
8
|
+ * @TODO
|
|
9
|
+ * @1. Go through the hamlet file , use Regular expressions (Regex)
|
|
10
|
+ * Replace all instances of the string "Hamlet" with "Leon"
|
|
11
|
+ * Replace all instances of the string "Horatio" with "Tariq"
|
|
12
|
+ * Breakdown all the logic to complete this process
|
|
13
|
+ * Must use Pattern && Matcher to replace the words ^Hint: replaceAll();^
|
7
|
14
|
*/
|
|
15
|
+// LOGIC
|
|
16
|
+// ==============
|
|
17
|
+// Iterate through the file
|
|
18
|
+// Use regular expressions/ Pattern & Matcher to target specific strings or matches of characters
|
|
19
|
+// in this case "Hamlet" & "Horatio"
|
|
20
|
+// After I've locked on to all targeted strings/characters then replace them,
|
|
21
|
+// Maybe replace them using the replaceAll(); function
|
8
|
22
|
public class HamletParser {
|
9
|
23
|
|
10
|
24
|
private String hamletData;
|
|
@@ -32,8 +46,14 @@ public class HamletParser {
|
32
|
46
|
return result.toString();
|
33
|
47
|
}
|
34
|
48
|
|
|
49
|
+ public String nameSwapper(String match, String newMatch, String nameInput){
|
|
50
|
+ Pattern namePattern = Pattern.compile(match); //instance class of pattern compressed version of Regex
|
|
51
|
+ Matcher nameMatch = namePattern.matcher(nameInput); //use my pattern object to make an instance of matcher, which will then parse my nameinput
|
|
52
|
+ return nameMatch.replaceAll(newMatch);
|
|
53
|
+ }
|
|
54
|
+
|
35
|
55
|
public String getHamletData(){
|
36
|
56
|
return hamletData;
|
37
|
57
|
}
|
38
|
58
|
|
39
|
|
-}
|
|
59
|
+}
|