|
@@ -28,13 +28,22 @@ public class HamletParser {
|
28
|
28
|
try
|
29
|
29
|
{
|
30
|
30
|
Scanner scanner = new Scanner(file);
|
|
31
|
+ Pattern p = Pattern.compile(("Hamlet"));
|
|
32
|
+ Pattern p2 = Pattern.compile("Horatio");
|
|
33
|
+
|
31
|
34
|
while(scanner.hasNextLine()){
|
32
|
|
- /*//String line = scanner.nextLine();
|
33
|
|
- //String updated = line.replaceAll("Hamlet","Leon");
|
34
|
|
- //line = updated.replaceAll("Horatio","Tariq");
|
35
|
|
- //result.append(line).append("\n");*/
|
36
|
|
- break;
|
|
35
|
+
|
|
36
|
+ String line = scanner.nextLine();
|
|
37
|
+ Matcher m = p.matcher(line);
|
|
38
|
+ String s = m.replaceAll("Leon");
|
|
39
|
+
|
|
40
|
+ Matcher m1 = p.matcher(s);
|
|
41
|
+ s = m1.replaceAll("Tariq");
|
|
42
|
+
|
|
43
|
+ result.append(s);
|
|
44
|
+
|
37
|
45
|
}
|
|
46
|
+
|
38
|
47
|
scanner.close();
|
39
|
48
|
}
|
40
|
49
|
catch(IOException e)
|
|
@@ -54,17 +63,17 @@ public class HamletParser {
|
54
|
63
|
Pattern p = Pattern.compile("hamlet", Pattern.CASE_INSENSITIVE);
|
55
|
64
|
Matcher m = p.matcher(inputLine);
|
56
|
65
|
|
57
|
|
- StringBuilder s = result.append(m.replaceAll("Leon"));
|
|
66
|
+ String s = m.replaceAll("Leon");
|
58
|
67
|
System.out.println(s);
|
59
|
|
- return s.toString();
|
|
68
|
+ return s;
|
60
|
69
|
|
61
|
70
|
}
|
62
|
|
- public StringBuilder ChangeHoratioToTariq(String inputLine)
|
|
71
|
+ public String ChangeHoratioToTariq(String inputLine)
|
63
|
72
|
{
|
64
|
73
|
//String line ;
|
65
|
|
- Pattern p = Pattern.compile("\\Horatio\\b", Pattern.CASE_INSENSITIVE);
|
|
74
|
+ Pattern p = Pattern.compile("Horatio", Pattern.CASE_INSENSITIVE);
|
66
|
75
|
Matcher m = p.matcher(inputLine);
|
67
|
|
- StringBuilder s = result.append(m.replaceAll("<h1>Tariq</h1>"));
|
|
76
|
+ String s = m.replaceAll("Tariq");
|
68
|
77
|
return s;
|
69
|
78
|
|
70
|
79
|
}
|