Selaa lähdekoodia

fixed issue, one error still

Tommy Rogers 6 vuotta sitten
vanhempi
commit
26e5a0e234
1 muutettua tiedostoa jossa 4 lisäystä ja 4 poistoa
  1. 4
    4
      src/main/java/HamletParser.java

+ 4
- 4
src/main/java/HamletParser.java Näytä tiedosto

39
     }
39
     }
40
 
40
 
41
     public String changeWord(String search, String replace){
41
     public String changeWord(String search, String replace){
42
-        Pattern patt = Pattern.compile("^" +search + "", Pattern.CASE_INSENSITIVE);
42
+        Pattern patt = Pattern.compile("\\b" +search + "\\b", Pattern.CASE_INSENSITIVE);
43
         Matcher m = patt.matcher(hamletData);
43
         Matcher m = patt.matcher(hamletData);
44
-        return m.replaceAll(replace);
44
+        return m.replaceAll("" + replace + "");
45
     }
45
     }
46
 
46
 
47
-    public int findWord(CharSequence hamletData ,String search) {
47
+    public int findWord(String hamletData ,String search) {
48
         int count = 0;
48
         int count = 0;
49
-        Pattern patt = Pattern.compile("^" +search + "", Pattern.CASE_INSENSITIVE);
49
+        Pattern patt = Pattern.compile("\\b" +search + "\\b", Pattern.CASE_INSENSITIVE);
50
         Matcher m = patt.matcher(hamletData);
50
         Matcher m = patt.matcher(hamletData);
51
      while (m.find())
51
      while (m.find())
52
             count++;
52
             count++;